Dear SAS experts
As a very simple example of my dataset, I would like to given a dataset like the following introduce a new observation as the 1st observation which only includes blanks/missing;
data have;
input Name $ Age num1 num2 num3;
datalines;
Maria 30 5 2 17
John 32 3 7 20
;
run;
It would be great to find a way to introduce the observation without having to specify "by hand" which variables are included in the dataset. I expect that I need to use some code which includes "then do" and "call missing (of _all_)", but I a cannot reach the desired code.
Can someone help?
Thank you
It's even easier:
data want;
output;
set have;
run;
Edit:
Explanation for @mgrasmussen:
Shouldn't be hard to do, but what possible purpose is there in putting forth the effort to achieve a blank line in a data set?
1) Why?
2) How:
data have;
input Name $ Age num1 num2 num3;
datalines;
Maria 30 5 2 17
John 32 3 7 20
;
run;
data want;
set have;
if _N_ = 1 then do;
call missing(of _all_);
output;
end;
output;
run;
With a little trickery with data step mechanics, it's easy:
data want;
if _n_ = 1 then output;
set have;
output;
run;
It's even easier:
data want;
output;
set have;
run;
Edit:
Explanation for @mgrasmussen:
I don't know WHY you would want to do this, but it's fairly simple:
data have;
/* First iteration only, write out a row before reading data */
if _n_=1 then output;
input Name $ Age num1 num2 num3;
/* Write out a row after each data read */
output;
datalines;
Maria 30 5 2 17
John 32 3 7 20
;
run;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.