BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
JC411911
Obsidian | Level 7

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;

 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User
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.

View solution in original post

5 REPLIES 5
Tom
Super User Tom
Super User

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;
JC411911
Obsidian | Level 7
Ah that worked. This may be nitpicky but is there a way to just get the text to list one time regardless if the statement is true and there are many observations? In that result I see "NEED CREDIT FILE AND LETTER" multiple times since there are hundreds of obrservations that meet the criteria.
ballardw
Super User
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.

Tom
Super User Tom
Super User

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;

 

Reeza
Super User

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;

 


 

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 5 replies
  • 666 views
  • 3 likes
  • 4 in conversation