Hi, how can I sort more then 2 datas same time by one variable which available in every data.
Your not really providing any information. What datasets do you mean, do they have a common name, like ds1 ds2 which we can use, will they all have different names, is it all datasets in a given library? If its all in a library then:
data _null_; set sashelp.vtable (where=(libname="YOURLIB")); call execute(cats('proc sort data=yourlib.',memname,'; by var1; run;')); run;
Assuming you mean datasets (and that they have the same structure), you can do this by creating a view and sorting that - eg:
data one;
x=1;y=2; output;
x=1;y=3; output;
data two;
x=4;y=6; output;
x=0;y=7; output;
data sortview /view=sortview;
set one two;
proc sort data=sortview out=final;
by x;
run;
Hi Allan Bowe, I mean all datas have same variable and need to sort before set
ok - I'm going to assume you didn't necessarily mean that the datasets had to be sorted at the same time (which is possible, using rsubmit or other techniques). If you are happy for the datasets to be sorted in sequence, here is a simple macro solution:
data one;
x=1;y=2; output;
x=1;y=3; output;
data two;
x=4;y=6; output;
x=0;y=7; output;
data three;
x=6;y=6; output;
x=6;y=7; output;
%macro sortandappend(datasets=,var=x,outds=outds);
%local i;
%do i=1 %to %sysfunc(countw(&datasets));
%let ds=%scan(&datasets,&i);
proc sort data=&ds;
by &var;
run;
%end;
data &outds;
set &datasets;
run;
%mend;
%sortandappend(datasets=one two three,var=x,outds=outds)
You provide a list of input datasets to the macro (one, two and three), set the variable to sort by, and the dataset to create.
what you think about this ?
%Macro VR(data, sort);
proc sort data=&data;
by &sort;
run;
%mend vr;
data rm;
length macro $100;
set sashelp.vtable;
where libname="WORK" and memname ~in("_SV", "__MVALLRAW");;
macro='%VR(' || strip(memname) || ", _PATIENT_DISPLAY_ID_FULL" || ");";
run;
%macro VV;
proc sql;
select macro into:macro separated by " " from rm;
quit;
¯o;
%mend VV;
%VV;
You can call the %vr macro with call execute() from the data step, the second macro is not needed.
Your not really providing any information. What datasets do you mean, do they have a common name, like ds1 ds2 which we can use, will they all have different names, is it all datasets in a given library? If its all in a library then:
data _null_; set sashelp.vtable (where=(libname="YOURLIB")); call execute(cats('proc sort data=yourlib.',memname,'; by var1; run;')); run;
Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.
Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.