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

Please help me to get the below output from the input data using SAS datastep or proc sql:

 

Input Data:

IDValue
1ABC
1Others
1Others
2Others
2Others
3ABC
3ABC
3ABC
4ABC
4Others
5Others

 

Output:

IDValue
1Hybrid
2Others
3ABC
4Hybrid
5Others

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
5 REPLIES 5
mkeintz
PROC Star

I have a good idea of how you might do this, but you have not specified the rule you wish to use to generate the displayed output from the sample input.

 

Please state the rule you want to apply - which of course is the first step in generating appropriate SAS code.

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
Vimal1010
Calcite | Level 5

So basically, if common value is there related to an ID then that value should be there with distinct ID in output table, similarly if different values are there for an ID then in output Hybrid should be published with that distinct ID.

mkeintz
PROC Star

@Vimal1010 wrote:

So basically, if common value is there related to an ID then that value should be there with distinct ID in output table, similarly if different values are there for an ID then in output Hybrid should be published with that distinct ID.


Thank you.  I think this code does what you want:

 

data want (drop=_:);
  set have;
  by id value notsorted;
  if first.id then _nvalue=1;
  else if first.value then _nvalue+1;
  if last.id;
  if _nvalue>1 then value='Hybrid';
run;
--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 5 replies
  • 685 views
  • 0 likes
  • 3 in conversation