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 data as below

 

Varlist   chg1 chg 2 chg3 chg 4

             yes    No   yes     No

             No     No   No       No

             Yes    No   No       No

 

Expecting as below add new column name patch and if any yes display yes else display no

 

Varlist   chg1 chg 2 chg3 chg 4   Patch

             yes    No   yes     No        yes

             No     No   No       No        No

             Yes    No   No       No        yes

 

my code:

 

data Patch.Unix_final;
set Patch.Unix_final;
    length  patch $4;
array col(*) &varList.;
do i=1 to dim(col);
        if col{i} in ('Yes') then Patch='Yes';

else patch ='No';
end;
run;

 

Thanks a lot.

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

Just solved one like this a few days ago. Move the = "No" part:

data Patch.Unix_final;
set Patch.Unix_final;
length  patch $4;
array col(*) &varList.;
patch ='No ';
do i=1 to dim(col);
  if col{i} in ('Yes') then Patch='Yes';
end;
run;

View solution in original post

3 REPLIES 3
Kurt_Bremser
Super User

Just solved one like this a few days ago. Move the = "No" part:

data Patch.Unix_final;
set Patch.Unix_final;
length  patch $4;
array col(*) &varList.;
patch ='No ';
do i=1 to dim(col);
  if col{i} in ('Yes') then Patch='Yes';
end;
run;
Reeza
Super User
Patch =  ifc(whichc('yes', of chg1-chg4), "yes", "no");

@radha009 wrote:

i have data as below

 

Varlist   chg1 chg 2 chg3 chg 4

             yes    No   yes     No

             No     No   No       No

             Yes    No   No       No

 

Expecting as below add new column name patch and if any yes display yes else display no

 

Varlist   chg1 chg 2 chg3 chg 4   Patch

             yes    No   yes     No        yes

             No     No   No       No        No

             Yes    No   No       No        yes

 

my code:

 

data Patch.Unix_final;
set Patch.Unix_final;
    length  patch $4;
array col(*) &varList.;
do i=1 to dim(col);
        if col{i} in ('Yes') then Patch='Yes';

else patch ='No';
end;
run;

 

Thanks a lot.




novinosrin
Tourmaline | Level 20
data have;
input (chg1 chg2 chg3 chg4) ($);
datalines;
yes    No   yes     No
No     No   No       No
Yes    No   No       No
;

data want;
set have;
array t(*) ch:;
patch=ifc('yes' in t,'yes','No');
run;

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 928 views
  • 3 likes
  • 4 in conversation