Вопрос

I have a dataset that has one column with a list of 45 variables - it is called "output". In another dataset, I have time series data on 200 variables. The name of the variables in on top in the first row and the values throughout time are in the columns. So for example I have unemployment on top for the name of the variable and the value of unemployment throughout time under that. Same for GDP and so on - this dataset is called "All".

I like to call 45 cariables from dataset "out" and make a smaller table out of "All" with only those 45 variables .

I used proc sql; create table TABLE, but I am not sure how to finish up the code. My idea was to define a list and bring in that list into proc sql to make the smaller table, however I couldn't get it to work.

I appreciate if someone can help with this. Thanks, SE

Это было полезно?

Решение

Here's a proc sql solution that's pretty simple.

proc sql noprint;
select col_name into :vars separated by ' ,'
from output;
quit;

proc sql;
create table want as select &vars.
from all;
quit;

Другие советы

One option is to concatenate a list of the variables into a macro variable and use that to keep what you want. Here's what I"m thinking:

data output;
    Input VariableName $;
    datalines;
    One
    Two
    Three
Run;

data a; *_NULL_;
    Retain VariableList;
    Length VariableList $1000;
    Set Output end=end;
    VariableList = Catx(" ", VariableList, VariableName) ;
    If End Then Call Symput('MyVariableList', VariableList);
run;

%put &MyVariableList;

data Want;
    Set All;
    Keep &MyVariableList ;
run;

You can use proc transpose in your 2nd dataset, since you don't provide much data I can offer a simple example of how you use the statement, please refer to this documentation for further information.

proc transpose data=work.narrow_file1
out=work.narrow_file1_transp_prefix
prefix=pet_count;
run;
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top