BookmarkSubscribeRSS Feed
radha009
Quartz | Level 8

Dear experts, Need help on looping column names (varlist) and create a new table with unique name and id.

 

 

proc contents data=patch.Windows_patch out=patch.contents noprint; run;

proc sql ;
   select name into :varlist separated by ' '
  from patch.contents where name like '%CHG%';
%let n=&obs;
quit;

 

proc sql;

do i = 1 to dim(Patch) ;
    create table Patch.Patch(i) as select unique a.Name, a.CI_ID, B.App, b.App_ID from Patch.Troux a, Patch.Win_servers b
        where a.CI_ID=b.App_ID and b.Patch(i) is not null order by a.Name;

end;
quit;

4 REPLIES 4
radha009
Quartz | Level 8

oops my subject got change on search.

Need help on looping column names (varlist) and create a new table with unique name and id.

 

 

proc contents data=patch.Windows_patch out=patch.contents noprint; run;

proc sql ;
   select name into :varlist separated by ' '
  from patch.contents where name like '%CHG%';
%let n=&obs;
quit;

 

proc sql;

do i = 1 to dim(Patch) ;
    create table Patch.Patch(i) as select unique a.Name, a.CI_ID, B.App, b.App_ID from Patch.Troux a, Patch.Win_servers b
        where a.CI_ID=b.App_ID and b.Patch(i) is not null order by a.Name;

end;
quit;

SuryaKiran
Meteorite | Level 14

Hi,

 

Are you trying to subset the data based on the list you  have in the macro variable. Try something like this:

proc sql;
select distinct age into:Age_dist separated by ','
from sashelp.class;
quit;
options symbolgen mprint mlogic;
%PUT &Age_Dist;
%Macro Subset();
%DO i=1 %to %SYSFUNC(Countw("&Age_Dist"));
%LET var=%SCAN(%BQUOTE(&Age_Dist),&i,',');
proc sql;
create table DS_&Var as 
select distinct name,age
from sashelp.class
where age=&Var;
quit;
%End;
%MEND Subset;
%subset();
Thanks,
Suryakiran
Reeza
Super User

Note the expert recommendation - don't do this. It makes your life harder down the road. 

 

If you're going to do it anyways, try the options here:

http://www.sascommunity.org/wiki/Split_Data_into_Subsets

 

https://blogs.sas.com/content/sasdummy/2015/01/26/how-to-split-one-data-set-into-many/

 

 

sas-innovate-2024.png

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.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 922 views
  • 0 likes
  • 3 in conversation