BookmarkSubscribeRSS Feed
hellohere
Pyrite | Level 9

When using PROC SQL/Select column into: Macro_Variable from dataset[on condition], how to 

tell whether the macro variable is created or not?!

 

"NOTE: No rows were selected." indicates no creattion. And later on, my code complains at collecting

the macro variable value. I need a logic to tell and remove the complain. 

MPRINT(COLLDIF):   select ind into: ind_min_dif_off25 from _reg_temp_summ_ts_t where ind > 932 and zz500_t0_dif_14--0.96968>2.5*0.011659
having ind=min(ind);
NOTE: The query requires remerging summary statistics back with the original data.
NOTE: No rows were selected.
4 REPLIES 4
FreelanceReinh
Jade | Level 19

Hello @hellohere,

 

I would check the value of the automatic macro variable SQLOBS, as this will work even if your macro variable ind_min_dif_off25 exists (e.g., defined as global), but contains an outdated value.

 

Example:

%macro test;
proc sql noprint;
select age into :mvar trimmed from sashelp.class
where name='Bob';
quit;
%if &sqlobs=0 %then %do;
  %put %str(WAR)NING: No rows were selected, hence MVAR was not updated.;
  /* ... whatever else needs to be done ... */
%end;
%mend test;
%test

 

PaigeMiller
Diamond | Level 26

Do NOT show us partial logs!!

 

Show us the COMPLETE log for this PROC SQL — showing the PROC SQL statement in the log all the way down to the last note after the PROC SQL. Always show us the complete log for whatever PROC is causing the problem — always.

 

Clearly, you are either accessing a data set which has zero observations, or you have a WHERE clause in PROC SQL that selects zero observations (or both). That's why you get the messages you are seeing.

--
Paige Miller
Ksharp
Super User

Macro function %symexis() could do this:

 

%macro test;
proc sql ;
select age into :mvar trimmed from sashelp.class
where name='Freelance';
quit;
%if %symexist(mvar) %then %do;
  %put  MVAR was updated.;
%end;
%else %put  MVAR was not created.;
%mend test;
%test

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and save with the early bird rate—just $795!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 4 replies
  • 114 views
  • 3 likes
  • 5 in conversation