BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
DivyaGadde
Fluorite | Level 6

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!

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26
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.

--
Paige Miller

View solution in original post

3 REPLIES 3
PaigeMiller
Diamond | Level 26
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.

--
Paige Miller
novinosrin
Tourmaline | Level 20

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;

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 514 views
  • 3 likes
  • 4 in conversation