BookmarkSubscribeRSS Feed
Siddhartha
Calcite | Level 5
I am having a library, in that there are five datasets with five variables each and having only one observation.Out of five variables one variable is numeric.
I want the data from all five datasets with a numeric variable.
How can I do this using datastep or a macro without knowing whether a variable is numeric?
Thanks in advance.

Regards,
Sidhu
2 REPLIES 2
data_null__
Jade | Level 19
I don't understand what you want. I will guess.

[pre]
* Example data;
data a1 a3 a4;
retain c1-c4 'Y' n1 1;
run;
data a2 a5;
retain d1-d4 'D' a 2;
run;
* Concatenate numeric variables;
data a;
set
a1(keep=_numeric_)
a2(keep=_numeric_)
a3(keep=_numeric_)
a4(keep=_numeric_)
a5(keep=_numeric_)
;
run;
proc print;
run;
[/pre]
1162
Calcite | Level 5
I just saw data_null_ beat me to it. Anyway . . .

This is an example of how I would do it, but it takes a couple steps. In this example, I create three datasets with different variable formats. After merging these sets, I determine the numeric variables using PROC CONTENTS and PROC SQL and then limit my final dataset to just those variables.

[pre]data a (keep=VarA:) b (keep=VarB:) c (keep=VarC:);
VarA1 = 8; VarA2 = 'Yes'; output a;
VarB1 = 'True'; VarB2 = 256; output b;
VarC1 = 'Positive'; VarC2 = 'Nebraska'; VarC3 = 87.9; output c;
run;

data x;
merge a b c;
run;

proc contents data=x out=contents (keep=name type) noprint;
run;

proc sql noprint;
select name into :varlst separated by ' ' from contents where type = 1;
quit;

data x;
set x;
keep &varlst;
run;
[/pre] Message was edited by: 1162

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 2 replies
  • 729 views
  • 0 likes
  • 3 in conversation