BookmarkSubscribeRSS Feed
dostiep
Calcite | Level 5

 

 Hi,

 

I was wondering why, when I add the option NOPRINT to PROC SQL, only the first line generated by the macro call from RESOLVE function is displayed in the LOG? I f I remove the NOPRINT option, all the expected lines are written in the LOG.

 

If you run the following code, you'll see only one line displayed in the LOG.

 

%macro warn(msg);

%put &msg;

%mend warn;

PROC SQL noprint;

SELECT RESOLVE('%warn( msg = name='||name||' age='||PUT(age,2.)||')') AS y

FROM sashelp.class

;

QUIT;

 

If you run it again but this time without the NOPRINT, you'll see all the lines displayed in the LOG.

 

Any reason why? Any workarounds?

 

Thanks

 

Pierre 

3 REPLIES 3
ChrisNZ
Tourmaline | Level 20

Because proc sql returns nothing to any destination, it just stops after the first record.

 

The same happens if you run 

 

proc sql noprint; 
  select ' ' as Y from SASHELP.CLASS;
quit;       
%put &=sqlobs;

Note that if you use the data in any way, all the table is read, but there must be an output.

 

 

These 3 steps will read the whole table:

 

proc sql noprint;   
  create table T as
  select resolve('%warn( msg = n1='||NAME||' age='||put(AGE,2.)||')')  as Y from SASHELP.CLASS;
quit;       %put &=sqlobs;

proc sql noprint; 
  select resolve('%warn( msg = n2='||NAME||' age='||put(AGE,2.)||')')  as Y into :tt separated by ',' from SASHELP.CLASS; 
quit;        %put &=sqlobs &=tt;   

proc sql ; 
  select resolve('%warn( msg = n3='||NAME||' age='||put(AGE,2.)||')')  as Y from SASHELP.CLASS;
quit;        %put &=sqlobs;

because proc sql outputs to a table, to macro variables and to the ODS destination respectively.

dostiep
Calcite | Level 5

The best solution I found so far is to create a _NULL_ table. It then reads all observations and avoid any unnecessary output to be generated:

 

PROC SQL noprint;

CREATE TABLE _NULL_ AS

SELECT RESOLVE('%warn( msg = name='||name||' age='||PUT(age,2.)||')') AS y

FROM sashelp.class

;

QUIT;

ChrisNZ
Tourmaline | Level 20

It would probably be even faster (I cant test atm) to create a single macro variable.

 

proc sql noprint; 
  select resolve('%warn( msg = n2='||NAME||' age='||put(AGE,2.)||')') as Y into :dummy from SASHELP.CLASS; 
quit; 

 

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
  • 3 replies
  • 4660 views
  • 0 likes
  • 2 in conversation