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

Hi All,

I need some help with the following:

This data is saved from some traditional source (Ms Word). Though one can do this easily in excel, I wonder how to do this in SAS. 

 

Have   Want
Category Item   Item Category
Dog     Sheepdogs Dog
  Sheepdogs   Pinschers Dog
  Pinschers   Terriers Dog
  Terriers   Dachshunds Dog
  Dachshunds Abyssinian Cat
Cat     Aegean Cat
  Abyssinian   Balinese Cat
  Aegean   Bambino Cat
  Balinese   Bengal Cat
  Bambino   Birman Cat
  Bengal      
  Birman      

 

Thanks, 
JAR

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

You can do like this

 

data have;
input Category $ 1-5 Item $ 7-20;
datalines;
Dog                 
      Sheepdogs     
      Sheepdogs     
      Pinschers     
      Terriers      
      Dachshunds    
Cat                 
      Abyssinian    
      Aegean        
      Balinese      
      Bambino       
      Bengal        
      Birman        
;

data want(drop=_:);
   set have;
   retain _;
   if not missing(Category) then _=Category;
   if not missing(Item);
   Category=_;
run;

View solution in original post

3 REPLIES 3
PeterClemmensen
Tourmaline | Level 20

You can do like this

 

data have;
input Category $ 1-5 Item $ 7-20;
datalines;
Dog                 
      Sheepdogs     
      Sheepdogs     
      Pinschers     
      Terriers      
      Dachshunds    
Cat                 
      Abyssinian    
      Aegean        
      Balinese      
      Bambino       
      Bengal        
      Birman        
;

data want(drop=_:);
   set have;
   retain _;
   if not missing(Category) then _=Category;
   if not missing(Item);
   Category=_;
run;
JAR
Obsidian | Level 7 JAR
Obsidian | Level 7

Thank you!

PeterClemmensen
Tourmaline | Level 20

Anytime, glad to help 🙂

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 480 views
  • 0 likes
  • 2 in conversation