BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
radha009
Quartz | Level 8

i have column names like  below, if data missing in that column insert null else insert App_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;

 

data work;

set have;

do i = 1 to &n ;
    if &Patch {i} =' ' then
        &patch{i}=' '
    else
        &patch{i}=App_ID;
end;
run;

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

And make the creation of varlist simpler:

proc sql noprint ;
select name into :varlist separated by ' '
from dictionary.columns
where
  libname = "PATCH" and
  memname = "WINDOWS_PATCH" and
  name like '%CHG%';
quit;

No proc contents needed.

View solution in original post

3 REPLIES 3
Reeza
Super User

Use a data step and an array instead. SQL doesn't lend itself well to variable lists and multiple variables well and then you can avoid using a macro entirely. 

 


@radha009 wrote:

i have column names like  below, if data missing in that column insert null else insert App_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;

 

data work;

set have;

do i = 1 to &n ;
    if &Patch {i} =' ' then
        &patch{i}=' '
    else
        &patch{i}=App_ID;
end;
run;

 

 

 

 


 

 

Reeza
Super User

Sorry, must have misread your question. You have everything you need to do this and you don't need macros. 

If the variables were listed side by side you could also use:

 

array PATCH(*) FirstVarName -- LastVarName;

 

 

data work;

set have;
array Patch (*) &varList.;

do i = 1 to dim(Patch) ;
    if not missing(patch(i)) then patch(i) = APP_ID;
end;


run;

 
Kurt_Bremser
Super User

And make the creation of varlist simpler:

proc sql noprint ;
select name into :varlist separated by ' '
from dictionary.columns
where
  libname = "PATCH" and
  memname = "WINDOWS_PATCH" and
  name like '%CHG%';
quit;

No proc contents needed.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 4561 views
  • 1 like
  • 3 in conversation