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

Hi, 

I know that I can use sqlobs to refer to the observations in the proc sql step. 

what is I am processing multiple proc sql steps? how do I differentiate the sqlobs from the first step to the sqlobs from the second step? Is there a way to name them?

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

Would copying the value to another macro var help?

 

like

 

%let sql_obs1= &sqlobs;

 

on the next proc sql

 

you could incremet 

 

and load %let sql_obs2= &sqlobs;

 

and so on

View solution in original post

3 REPLIES 3
novinosrin
Tourmaline | Level 20

Would copying the value to another macro var help?

 

like

 

%let sql_obs1= &sqlobs;

 

on the next proc sql

 

you could incremet 

 

and load %let sql_obs2= &sqlobs;

 

and so on

ballardw
Super User

@laiguanyu001 wrote:

Hi, 

I know that I can use sqlobs to refer to the observations in the proc sql step. 

what is I am processing multiple proc sql steps? how do I differentiate the sqlobs from the first step to the sqlobs from the second step? Is there a way to name them?


If you currently have multiple SELECT clauses in a single Proc SQL step then you would need to modify the code to one Select per Sql call and assign the resulting sqlobs to a separate macro variable. Something like:

proc sql;
   select clause
   from source
   ;
quit;
%let count1 = &sqlobs.;
proc sql;
   select clause2
   from source2
   ;
quit;
%let count2 = &sqlobs.;

Possibly more descriptive names than Count1 and Count2 would be good idea to better identify the source.

 

Tom
Super User Tom
Super User

Just store the value.

proc sql noprint;
select distinct name into :male_names separated by ' '
from sashelp.class
where sex='M'
;
%let num_males=&sqlobs;
select distinct age  into :male_ages separated by ' ' 
from sashelp.class 
where sex='M'
;
%let num_male_ages=&sqlobs;
quit;

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!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 964 views
  • 1 like
  • 4 in conversation