Hello,
I have a fairly simple program that I need to create that will display text depending on two conditions of a dataset. The program runs but the text is not displayed in the results window but rather in the log. How can I write the below to get the text to show once the program is run without having to look in the log?
data _NULL_; set me.prim_data nobs=numobs; if numobs>0 and payment_channel = 'CREDIT' then PUT 'NEED CREDIT FILE AND LETTER'; RUN;
data _NULL_;
file print;
if numobs=0 then put 'FILE IS EMPTY';
set me.prim_data nobs=numobs;
retain flag 0;
if payment_channel = 'CREDIT' and flag=0 then do;
PUT 'NEED CREDIT FILE AND LETTER';
flag=1;
stop;
end;
run;
The retain keeps a variable's value across iteration of the data step. So initialize to 0, in example, and then the first time you execute the Put change the value to something else.
Just add a FILE statement to tell the data step where you want it to go.
For example use FILE PRINT to write to whatever ODS destinations you have open.
Note you cannot test for NUMOBS=0 after the SET statement because if it is zero then the SET statement is the last statement that will execute because it will read past the end of the input.
data _NULL_;
file print;
if numobs=0 then put 'FILE IS EMPTY';
set me.prim_data nobs=numobs;
if payment_channel = 'CREDIT' then PUT 'NEED CREDIT FILE AND LETTER';
run;
Do you really want to write that message for every observation that has payment_channel equal to CREDIT?
How many observations are in that dataset? You might want to stop at the first one.
data _NULL_;
file print;
if numobs=0 then put 'FILE IS EMPTY';
set me.prim_data nobs=numobs;
if payment_channel = 'CREDIT' then do;
PUT 'NEED CREDIT FILE AND LETTER';
stop;
end;
run;
data _NULL_;
file print;
if numobs=0 then put 'FILE IS EMPTY';
set me.prim_data nobs=numobs;
retain flag 0;
if payment_channel = 'CREDIT' and flag=0 then do;
PUT 'NEED CREDIT FILE AND LETTER';
flag=1;
stop;
end;
run;
The retain keeps a variable's value across iteration of the data step. So initialize to 0, in example, and then the first time you execute the Put change the value to something else.
Just STOP.
Even easier if you use a WHERE statement.
data _null_:
file print;
if 0=numobs then put 'None found';
set mydata nobs=numobs;
where (xx='CHECK');
put 'Found some.';
stop;
run;
Use CALL EXECUTE + PROC ODSTEXT
data _NULL_;
set sashelp.class nobs=numobs;
if numobs>0 then call execute("proc odstext;
p 'NEED CREDIT FILE AND LETTER' / style=[color=red fontsize=25pt];
run;");
RUN;
@JC411911 wrote:
Hello,
I have a fairly simple program that I need to create that will display text depending on two conditions of a dataset. The program runs but the text is not displayed in the results window but rather in the log. How can I write the below to get the text to show once the program is run without having to look in the log?
data _NULL_; set me.prim_data nobs=numobs; if numobs>0 and payment_channel = 'CREDIT' then PUT 'NEED CREDIT FILE AND LETTER'; RUN;
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.