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.
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
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.
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
April 27 – 30 | Gaylord Texan | Grapevine, Texas
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!
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.
Ready to level-up your skills? Choose your own adventure.