if I have 1 observation from a proc sql query how do i assign that to a variable? that i want to load into a variable
proc sql outobs=1;
SELECT "Qa Test Id"n FROM ROBM.QUAL102;
run
so that further on I can do the below sort if the &var (QA Test ID) from the select above is 35 for instance
if &var = 35 then do; proc sort data=ROBM.QUAL102; by TERM_CODE "Id"n CRN; quit; end;
I think you are looking to create a macro variable. If so there is no need for the OUTOBS setting since unless you tell it to generate multiple variables or make a delimited list it will only write out one value into the macro variable.
proc sql noprint;
SELECT "Qa Test Id"n
into :mvar
FROM ROBM.QUAL102
;
quit;
You can then test the macro variable, but to conditionally generate code you will need to wrap the code into a macro o ruse some other method to generate the code. IF/THEN statements only work in DATA STEPS or some procs that support data step like data processing code.
%macro xxx ;
%if (&mvar = 35) %then %do;
proc sort data=ROBM.QUAL102;
by TERM_CODE "Id"n CRN;
run;
%end;
%mend xxx;
%xxx;
You need to create a macro variable not a outobs=1 or create a dataset. Your current code will only output the data to the result window.
proc sql noprint;
select max(age) into :max_age
from sashelp.class;
quit;
%put &max_age;
I think you are looking to create a macro variable. If so there is no need for the OUTOBS setting since unless you tell it to generate multiple variables or make a delimited list it will only write out one value into the macro variable.
proc sql noprint;
SELECT "Qa Test Id"n
into :mvar
FROM ROBM.QUAL102
;
quit;
You can then test the macro variable, but to conditionally generate code you will need to wrap the code into a macro o ruse some other method to generate the code. IF/THEN statements only work in DATA STEPS or some procs that support data step like data processing code.
%macro xxx ;
%if (&mvar = 35) %then %do;
proc sort data=ROBM.QUAL102;
by TERM_CODE "Id"n CRN;
run;
%end;
%mend xxx;
%xxx;
that works great thanks
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 25. Read more here about why you should contribute and what is in it for you!
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.