Hi Everyone,
What I am trying to do is use an empty dataset as a "frame" (to set the variable order and lengths) and then append observations to that dataset with hardcoded data (using <variable>=<value> and output statements). However, when I set the empty dataset and then try to add the variable and output statements, the resulting dataset always still has 0 observations.
Here is some example code, in which the "_out.WSTHP" is the original empty dataset (0 observations, but contains all of the variables that are described below) and I am trying to add an observation containing the subsequent data. I would have thought the hardcoded lines and output statement would create an observation, but the resulting dataset is still empty.
Any ideas?
data _out.WSTHIP; set _out.WSTHIP; __StudyOID="dummy"; __MetaDataVersionOID="1.3"; __SubjectKey="dummy-102"; __StudyEventOID="e_fu10y"; __StudyEventRepeatKey="001"; __FormOID="f_metabpar"; __FormRepeatKey="001"; __ItemGroupOID="g_wsthip"; __ItemGroupRepeatKey="001"; __LocationOID="Center.Admin"; __UserOID="User.034"; HIP=201; WSTHIP=1; WAIST=201; output; run;
As it stands, the SET statement ends the DATA step because there are no observations to read. Yet you need the SET statement within the DATA step to define the variables properly. The solution is to keep the SET statement within the DATA step, yet avoid executing it. For example, change it to:
if 5=4 then set _out.WSTHIP;
As it stands, the SET statement ends the DATA step because there are no observations to read. Yet you need the SET statement within the DATA step to define the variables properly. The solution is to keep the SET statement within the DATA step, yet avoid executing it. For example, change it to:
if 5=4 then set _out.WSTHIP;
Thanks for the suggestion! That did the trick!! 🙂
Thanks again!
Yes, thats normal. There are no obs being read, so nothing happens in the datastep. Either create a datastep with your one record, then append or set that with your template, or you could use proc sql; insert into out.wthip __studyoid="abc"...; quit;
You can use next skilton code:
data _out.WSTHIP; set _out.WSTHIP end=eof;
output;
if eof then do;
.... enter here your code to assign new obs values...
output;
end;
run;
Thanks for the suggestion! I actually saw this method somewhere and tried it, but it still generated a 0 observation dataset. I did get another suggestion in this thread that worked, but thanks anyway!!
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.