BookmarkSubscribeRSS Feed
ssc
Calcite | Level 5 ssc
Calcite | Level 5
Hi all,

I'm trying to append a single observation containing the value of a macro variable to an existing data set. My code (see below) works fine as long my input data set contains at least one observation, but fails if not.

Due to the context my program will run, I'm looking for a solution which works and
- ensures that type and length of data set variable VALUE in OUT is equal to INPUT
- does not need creating temporary data sets

Does anyone have an idea for a simple solution?

Many thanks!

Regards,
Stephan

/** sas code begin *******************************************/
%let mvar=test;

data INPUT; /*works */
length value $20;
value="obs1";
run;

data INPUT; /*works not*/
length value $20;
delete;
run;


data OUT;
set INPUT end=eof;
output;
if(eof) then do;
value=symget('mvar');
output;
end;
run;

/** sas code end *******************************************/
2 REPLIES 2
data_null__
Jade | Level 19
[pre]
%let mvar=test;

data INPUT; /*works */
length value $20;
do _n_ = 1 to 10;
value="obs1";
output;
end;
run;

data INPUT; /*works not*/
length value $20;
delete;
run;* cancel;


data OUT;
do while(not eof);
set INPUT end=eof;
output;
end;
value=symget('mvar');
output;
stop;
run;
proc print;
run;
[/pre]

To make it more APPEND like where you just add data to the end MODIFY is a good choice.

[pre]
data input;
if 0 then modify input;
value=symget('mvar');
output;
stop;
run;
[/pre] Message was edited by: data _null_;
DataShare
SAS Employee
Other way,

data OUT ;
if nc eq 0 or eof then
do;
value=symget('mvar');
output;
end;
set INPUT nobs=nc end=eof;
output;
run;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 941 views
  • 0 likes
  • 3 in conversation