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

 

I am looking for edit the data GiftOriginal.

 

In the column Toy where a observation appear less then 3  times(Bicycle and Plane) I want to rename "diverse".

 

The data ManuallyFormated is what I am looking for as a result.

 

Any idea how I can do that?

 


data GiftOriginal;
input ID$ toy$ town$;
cards;
Jensen Doodle Columbus
Tom Car Dayton
Mathew Truck Columbus
Zhin Doodle Columbus
Gylbert Car Columbus
Luke Bicycle Columbus
Barbara Doodle Columbus
Judy Doodle Dayton
Dennis Truck Dayton
Anthony Car Dayton
Ian Plane Dayton
Ruan Car Dayton
Santiago Truck Dayton
Uin Doodle Columbus
Josh Car Columbus
run;

data ManuallyFormated;
input ID$ toy$ town$;
cards;

Jensen Doodle Columbus
Tom Car Dayton
Mathew Truck Columbus
Zhin Doodle Columbus
Gylbert Car Columbus
Luke DIVERSE Columbus
Barbara Doodle Columbus
Judy Doodle Dayton
Dennis Truck Dayton
Anthony Car Dayton
Ian DIVERSE Dayton
Ruan Car Dayton
Santiago Truck Dayton
Uin Doodle Columbus
Josh Car Columbus

run;

 

1 ACCEPTED SOLUTION

Accepted Solutions
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Yes, I edited my post.  It should work with that data though you would need to change B.CNT < 3 to be B.CNT <= 3 for your logic.

View solution in original post

4 REPLIES 4
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Ok,didnt see the less than 3 part, try:

data GiftOriginal;
  input ID$ toy$ town$;
cards;
Jensen Doodle Columbus
Tom Car Dayton
Mathew Truck Columbus
Zhin Doodle Columbus
Gylbert Car Columbus
Luke Bicycle Columbus
Barbara Doodle Columbus
Judy Doodle Dayton
Dennis Truck Dayton
Anthony Car Dayton
Ian Plane Dayton
Ruan Car Dayton
Santiago Truck Dayton
Uin Doodle Columbus
Josh Car Columbus
run;

proc sql;
  create table WANT as 
  select A.ID,
         case when B.CNT < 3 then "DIVERSE" else A.TOY end as TOY,
         A.TOWN
  from   GIFTORIGINAL A
  left join (select TOY,count(TOY) as CNT from GIFTORIGINAL group by TOY) B
  on     A.TOY=B.TOY;
quit;
Giovani
Obsidian | Level 7

Hi RW9,

 

I edited the sample data to clarify.

If the toy appears once(plane), twice(bicycle), and or 3 times(truck) I would like to format and rename to diverse:

 

data GiftOriginal;
input ID$ toy$ town$;
cards;
Jensen Doodle Columbus
Tom Car Dayton
Mathew Truck Columbus
Zhin Doodle Columbus
Gylbert Car Columbus
Luke Bicycle Columbus
Barbara Doodle Columbus
Judy Doodle Dayton
Dennis Truck Dayton
Anthony Car Dayton
Ian Plane Dayton
Ruan Car Dayton
Santiago Truck Dayton
Uin Doodle Columbus
Josh Car Columbus
Bob Bicycle Columbus
run;

 

 

data ManuallyFormated;
input ID$ toy$ town$;
cards;

Jensen Doodle Columbus
Tom Car Dayton
Mathew DIVERSE Columbus
Zhin Doodle Columbus
Gylbert Car Columbus
Luke DIVERSE Columbus
Barbara Doodle Columbus
Judy Doodle Dayton
Dennis DIVERSE Dayton
Anthony Car Dayton
Ian DIVERSE Dayton
Ruan Car Dayton
Santiago DIVERSE Dayton
Uin Doodle Columbus
Josh Car Columbus
Bob  DIVERSE Columbus


run;

 

 

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Yes, I edited my post.  It should work with that data though you would need to change B.CNT < 3 to be B.CNT <= 3 for your logic.

Giovani
Obsidian | Level 7

RW9,

 

Thanks a lot.

 

You are great!!!

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 connect to databases in SAS Viya

Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 4 replies
  • 747 views
  • 0 likes
  • 2 in conversation