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: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1902 views
  • 2 likes
  • 4 in conversation