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

Hi Team,

 

I have a data like below

Subject category subcategory location visitnum severity wanted_flag

100 UAE Dubai Sharja 90 MILD N

100 UAE Dubai Sharja 20 MILD N

101 UAE Dubai Abudabi 90 MILD Y

101 UAE Dubai Abudabi 20 MODERATE Y

102 UAE Dubai Al Ain 20 MODERATE Y

102 UAE Dubai Kuwait 20 MODERATE Y

102 IND MUMBAI Delhi 20 MILD Y

103 IND Chennai Kolkata 90 MODERATE N

103 IND Chennai Kolkata 20 MODERATE N

 

The needed flag is also created above. Any help appreciated 

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

Try this

 

data have;
input Subject category $ subcategory $ location $ visitnum severity $;
datalines;
100 UAE Dubai Sharja  90 MILD     
100 UAE Dubai Sharja  20 MILD     
101 UAE Dubai Abudabi 90 MILD     
101 UAE Dubai Abudabi 20 MODERATE 
;

proc sql;
   create table want as
   select *
        , ifc(count(distinct severity) > 1, 'Y', 'N') as flag 
   from have
   group by Subject, category, subcategory
   ;
quit;

 

Result:

 

Subject category subcategory location visitnum severity flag
100     UAE      Dubai       Sharja   90       MILD     N
100     UAE      Dubai       Sharja   20       MILD     N
101     UAE      Dubai       Abudabi  90       MILD     Y
101     UAE      Dubai       Abudabi  20       MODERATE Y

View solution in original post

2 REPLIES 2
PeterClemmensen
Tourmaline | Level 20

Try this

 

data have;
input Subject category $ subcategory $ location $ visitnum severity $;
datalines;
100 UAE Dubai Sharja  90 MILD     
100 UAE Dubai Sharja  20 MILD     
101 UAE Dubai Abudabi 90 MILD     
101 UAE Dubai Abudabi 20 MODERATE 
;

proc sql;
   create table want as
   select *
        , ifc(count(distinct severity) > 1, 'Y', 'N') as flag 
   from have
   group by Subject, category, subcategory
   ;
quit;

 

Result:

 

Subject category subcategory location visitnum severity flag
100     UAE      Dubai       Sharja   90       MILD     N
100     UAE      Dubai       Sharja   20       MILD     N
101     UAE      Dubai       Abudabi  90       MILD     Y
101     UAE      Dubai       Abudabi  20       MODERATE Y
ambadi007
Quartz | Level 8
Now Iam getting "N" for if the same Subject same category and Same subcategory same visits
and with different location . This Should be Y .. also if a subject is present with only one visits as well then also should get Y

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