BookmarkSubscribeRSS Feed
pavank
Quartz | Level 8
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

 

3 REPLIES 3
PaigeMiller
Diamond | Level 26

@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.

--
Paige Miller
Tom
Super User Tom
Super User

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;

sas-innovate-white.png

Missed SAS Innovate in Orlando?

Catch the best of SAS Innovate 2025 — anytime, anywhere. Stream powerful keynotes, real-world demos, and game-changing insights from the world’s leading data and AI minds.

 

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
  • 3 replies
  • 636 views
  • 2 likes
  • 4 in conversation