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

I've got a short program that has two proc sql statements in it.

 

The first one will return a small 1 column dataset. I've then got a macro that looks at the number of observations returned by the proc sql. It will do different things depending on if there is more than 1 observation returned. Returning just one observation will cause a Data statement to run and show an output I want. If more than 1 observation is returned then I'm running another proc sql statement.

 

I don't want to display the results of the first proc sql but I do want to display the results of the second. 

 

However if I add a noprint option to the first proc sql then my program doesn't show either result. That isn't the behaviour I was expecting from noprint so I'm a bit confused.

 

I can't share any of my code on here unfortunately, so I've tried to explain it as fully as I could.

 

Can anyone help please?

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

You can turn the NOPRINT (and other options) on/off in the same PROC SQL step using the RESET statement.

For example this code will print only one list to the output.

proc sql noprint;
select name into :name_list separated by ' ' from sashelp.class where sex='M';
reset print;
select name into :name_list separated by ' ' from sashelp.class where sex='M';
reset noprint;
select name into :name_list separated by ' ' from sashelp.class where sex='M';
quit;

 

View solution in original post

4 REPLIES 4
ballardw
Super User

Show your code. Change anything that might be sensitive such as file path and name, variables, libraries or data set names to "generic" such as "c:\path\file.txt", var1, var2, LIB1, data1.

 

Once you have a "macro" involved locations of specific coding elements become very important since that generates code and you may have something buried in the macro that is setting options you forget.

Reeza
Super User

Are you ending your queries with a QUIT or RUN? If not, try ending each query with a quit first.

 


@jamesBFD wrote:

I've got a short program that has two proc sql statements in it.

 

The first one will return a small 1 column dataset. I've then got a macro that looks at the number of observations returned by the proc sql. It will do different things depending on if there is more than 1 observation returned. Returning just one observation will cause a Data statement to run and show an output I want. If more than 1 observation is returned then I'm running another proc sql statement.

 

I don't want to display the results of the first proc sql but I do want to display the results of the second. 

 

However if I add a noprint option to the first proc sql then my program doesn't show either result. That isn't the behaviour I was expecting from noprint so I'm a bit confused.

 

I can't share any of my code on here unfortunately, so I've tried to explain it as fully as I could.

 

Can anyone help please?


 

Tom
Super User Tom
Super User

You can turn the NOPRINT (and other options) on/off in the same PROC SQL step using the RESET statement.

For example this code will print only one list to the output.

proc sql noprint;
select name into :name_list separated by ' ' from sashelp.class where sex='M';
reset print;
select name into :name_list separated by ' ' from sashelp.class where sex='M';
reset noprint;
select name into :name_list separated by ' ' from sashelp.class where sex='M';
quit;

 

jamesBFD
Obsidian | Level 7
Thanks, the reset print statement worked perfectly.

SAS Innovate 2025: Call for Content

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 16. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 4 replies
  • 1743 views
  • 2 likes
  • 4 in conversation