DATA Step, Macro, Functions and more

want to disply all values

Accepted Solution Solved
Reply
Contributor
Posts: 33
Accepted Solution

want to disply all values

[ Edited ]

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;


Accepted Solutions
Solution
‎02-28-2017 03:45 PM
Super User
Posts: 7,760

Re: want to disply all values

[ Edited ]
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
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers

View solution in original post


All Replies
Frequent Contributor
Posts: 75

Re: want to disply all values

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;
Contributor
Posts: 33

Re: want to disply all values

Posted in reply to nehalsanghvi

yes something similar.it worked.Thanks you

Solution
‎02-28-2017 03:45 PM
Super User
Posts: 7,760

Re: want to disply all values

[ Edited ]
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
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Valued Guide
Posts: 505

Re: want to disply all values

Posted in reply to KurtBremser
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


☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 171 views
  • 2 likes
  • 4 in conversation