Hello,
I have dataset A(around 180 variables) with a list of variables that needs to be flagged in another data set B(a huge dataset with millions of records).
Dataset A data set B
A A B C D
C 10 20 30 40
D
I needed something like :
dataset needed: dataset c
A C D
10 30 40
Thank you for all your help and guidance!
proc sql noprint;
select distinct varname into :varnames separated by ' ' from a;
quit;
data c;
set b(keep=&varnames);
run;
This assumes (because you didn't tell us) that the variable name in Data Set A is VARNAME.
proc sql noprint;
select distinct varname into :varnames separated by ' ' from a;
quit;
data c;
set b(keep=&varnames);
run;
This assumes (because you didn't tell us) that the variable name in Data Set A is VARNAME.
HI @DivyaGadde This is a good question to learn and apply the SET Operators with CORR(corresponding variables) append aka UNION. Of course, you need a slight data processing to get the needed variables in horizontal. Also, for assigning datatypes, you may have to use PROC DATASETS for accurate results.
Example using your sample-
data a;
input vars $;
cards;
A
C
D
;
data b;
input a b c d;
cards;
10 20 30 40
;
proc transpose data=a out=need_vars(drop=_name_);
id vars;
run;
proc sql;
create table want as
select *
from need_vars
union all corr
select * from b;
quit;
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.