Hi,
I want to create a dataset that looks like this
data out;
input id description $ num_of_errors error $;
datalines;
1001 some_string &count_of_record some_error
;
data table1;
input test;
datalines;
1
2
3
;
here I want &count_of_record to be the number of rows from table1. so when I print the data out,
the result will look like this
id description num_of_error error
1001 some_string 3 some_error
I'm wondering if there's a programming way to do this instead of manually type in. Thanks!
No macro needed. Basic manipulation of data rarely requires macros.
proc summary data=table1;
var test;
output out=ntable n=num_of_errors;
run;
data out;
if _n_=1 then set ntable(drop=_:);
input id description $ error $;
datalines;
...
;
run;
Also, you can't have macro variables inside DATALINES
No macro needed. Basic manipulation of data rarely requires macros.
proc summary data=table1;
var test;
output out=ntable n=num_of_errors;
run;
data out;
if _n_=1 then set ntable(drop=_:);
input id description $ error $;
datalines;
...
;
run;
Also, you can't have macro variables inside DATALINES
thanks!! But what if my table1 also has some character values? I don't think proc summary works in that case.
@laiguanyu001 wrote:
But what if my table1 also has some character values?
Llittle known fact, if you omit the VAR command, PROC SUMMARY will count the number of observations, even if there are only character variables.
proc summary data=have;
output out=_stats_ ;
run;
Nearly 200 sessions are now available on demand in the Innovate Hub.
Watch Now →SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.