i want to display all values in macro.its taking only 1st value
proc sql;
select mem ,name into:ds,:var from dictionary.columns
where libname="RAW" and (name like '%AT' ') ;
quit;
proc sql;
select count(name)into:N from demo;
quit;
%macro loop(N,ds,var);
%do i= 1 %to &N;
%put "&ds" -"&var";
%end;
%mend;
proc sql;
select memname into:ds separated by " " from dictionary.columns
where libname="RAW" and (name like '%AT');
select name into:var separated by " " from dictionary.columns
where libname="RAW" and (name like '%AT');
quit;
%macro loop;
%do i = 1 %to %sysfunc(countw(&ds));
%put %scan(&ds,&i) -%scan(&var,&i);
%end;
%mend;
%loop
It's hard to provide a solution without any input data to work with or desired output data to look at. Can you send that along with the code?
You have specified only one macro variable per column you are selecting. So the query takes the values from the two columns from the first row only and puts them in those two macro variables.
Are you trying to print all column names from a dataset in one long string? Like this: ds1 has var1, var2, var3
Or do you want to print something like this in the log?
ds1 has var1
ds1 has var2
ds1 has var3
Here's a solution for the second option above:
proc sql;
select count(*) into :rowcount trimmed
from dictionary.columns
where libname="RAW"
and (name like '%AT') ;
quit;
proc sql;
select mem,name into :ds1-:ds&rowcount., :var1-:var&rowcount.
from dictionary.columns
where libname="RAW"
and (name like '%AT') ;
quit;
%macro loop;
%do i= 1 %to &rowcount.;
%put "&&ds&i" have "&&var&i";
%end;
%mend;
%loop;
yes something similar.it worked.Thanks you
proc sql;
select memname into:ds separated by " " from dictionary.columns
where libname="RAW" and (name like '%AT');
select name into:var separated by " " from dictionary.columns
where libname="RAW" and (name like '%AT');
quit;
%macro loop;
%do i = 1 %to %sysfunc(countw(&ds));
%put %scan(&ds,&i) -%scan(&var,&i);
%end;
%mend;
%loop
I have not paid much attention to this post so maybe I am off base, but this seems to work
* create some data;
libname sd1 "d:/sd1";
data sd1.xat(keep=sat rat bat) sd1.zat(keep= hat fat);
retain sat rat bat hat fat 0;
run;quit;
proc sql;
select
catx('-',memname,name)
into
:libnam separated by " "
from
dictionary.columns
where
libname="SD1"
and (name like '%AT')
;quit;
XAT-SAT
XAT-RAT
XAT-BAT
ZAT-HAT
ZAT-FAT
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.