BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Sathish_jammy
Lapis Lazuli | Level 10

Hi Experts, 

 

I need to create the group type in numbers for the following dataset

 

data have;
input G_Type$10.;
cards;
ABI
ABI
BIG
BIG
BIG
RET
run;

Expected output:

G_Type Want
ABI 1
ABI 1
ABI 1
BIG 2
BIG 2
BIG 2
RET 3

 

 

Thanks in advance!

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

If your data is sorted, do this

 

data want;
   set have;
   by G_Type;
   if first.G_Type then want + 1;
run;

View solution in original post

2 REPLIES 2
PeterClemmensen
Tourmaline | Level 20

If your data is sorted, do this

 

data want;
   set have;
   by G_Type;
   if first.G_Type then want + 1;
run;
RichardDeVen
Barite | Level 11

G_TYPE appears to be already ordered in an ascending manner.

 

Is there a reason you can't use G_TYPE directly?

Are you using 'want' to maintain original G_TYPE order ?

sas-innovate-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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