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

 

I have this dataset (have) with number combinations in column b. 

If column b contains the numbers 100, 200, 100 and 200, it should give the tag ="check". 

If column b contains a combination of 100 and not 200, it should give no tag.

 

Can this be possible in one data step? 

 

Code is below:


data have;
input a b :$32.;
cards;
1 100-100
2 300
3 200-100
4 300-300-300-100
5 200
;
run;

 

/*If b in ('100', '200') then tag = "check"*/

data want;
input a b :$32. tag $5.;
cards;
1 100-100 tag
2 300
3 200-100 tag
4 300-300-100
5 200 tag
;
run;

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User
data have;
input a b :$32.;
cards;
1 100-100
2 300
3 200-100
4 300-300-300-100
5 200
;
run;

data want;
set have;
marker_100 = 0;
marker_else = 0;
do i = 1 to countw(b,'-');
  if scan(b,i,'-') in ('100','200')
  then marker_100 = 1;
  else marker_else = 1;
end;
if marker_100 and not marker_else then tag = 'tag';
drop i marker_100 marker_else;
run;

View solution in original post

2 REPLIES 2
Kurt_Bremser
Super User
data have;
input a b :$32.;
cards;
1 100-100
2 300
3 200-100
4 300-300-300-100
5 200
;
run;

data want;
set have;
marker_100 = 0;
marker_else = 0;
do i = 1 to countw(b,'-');
  if scan(b,i,'-') in ('100','200')
  then marker_100 = 1;
  else marker_else = 1;
end;
if marker_100 and not marker_else then tag = 'tag';
drop i marker_100 marker_else;
run;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 2 replies
  • 746 views
  • 0 likes
  • 2 in conversation