Calcite | Level 5

## 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?

Regards,
Sidhu
2 REPLIES 2

## 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]
Calcite | Level 5

## 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=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
Discussion stats
• 2 replies
• 757 views
• 0 likes
• 3 in conversation