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

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.

 

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
  • 708 views
  • 0 likes
  • 3 in conversation