proc sql noprint;
select name into :mvar1 - :mvar99
from sashelp.class
;
quit;
%macro printMvars();
%do i=1 %to &sqlobs;
%put &&mvar&i;
%end;
%mend;
%printMvars()
i want to print list of values line by line without macro do loop using proc sql into clause block only
required output
Alfred
Alice
Barbara
Carol
Henry
James
Jane
Janet
Jeffrey
John
Joyce
Judy
Louise
Mary
Philip
Robert
Ronald
Thomas
William
Why so complicated? A simple SELECT will do it:
proc sql;
select name from sashelp.class;
quit;
@pavank wrote:
proc sql noprint; select name into :mvar1 - :mvar99 from sashelp.class ; quit; %macro printMvars(); %do i=1 %to &sqlobs; %put &&mvar&i; %end; %mend; %printMvars()
i want to print list of values line by line without macro do loop using proc sql into clause block only
Why do you even specify using SQL and macros here? You make your programming harder by specifying it has to be done a certain way.
You could use PROC PRINT. You should be specifying the output you want, rather than using a specific PROC and the INTO clause.
If the goal is to list the name to the SAS log then skip the SQL and the macro code code.
data _null_;
set sashelp.class;
put name;
run;
If you have a set of macro variables with a common prefix and numeric suffix then you can also print them to the log using a data step.
data _null_;
do i=1 to &sqlobs;
value = symget(cats('mvar',i));
put value;
end;
run;
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.