DATA Step, Macro, Functions and more

Data from five data steps with a numeric variable

Reply
Contributor
Posts: 69

Data from five data steps with a numeric variable

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
Respected Advisor
Posts: 3,777

Re: Data from five data steps with a numeric variable

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]
Frequent Contributor
Posts: 95

Re: Data from five data steps with a numeric variable

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=VarASmiley Happy b (keep=VarBSmiley Happy c (keep=VarCSmiley Happy;
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
Ask a Question
Discussion stats
  • 2 replies
  • 147 views
  • 0 likes
  • 3 in conversation