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

Hi all,

I have a data set like this one:

   var1   var 2         number

     aa     x                 1

     aa     y                 1 

     aa     z                 1

     bb     t                  2

     bb     y                 2

     cc                        3

     cc                        3

     cc                        3

so, the column number is the column that I want to obtain. As you can see, it assigns a number for each of distinct values of var1.

could you please help me????

thanks a lot

1 ACCEPTED SOLUTION

Accepted Solutions
AncaTilea
Pyrite | Level 9

Hi.

How about this?

data in;

input var1 $ var2 $;

cards;

aa x

aa y

aa z

bb t

bb y

cc .

cc .

cc .

;

proc sort data = in;by var1;

data temp; 

    set in;

    by var1;

    retain number 0;

    if first.var1 then number++ 1;retain number;

run;

I hope it helps!

Good luck.

Anca.

View solution in original post

2 REPLIES 2
AncaTilea
Pyrite | Level 9

Hi.

How about this?

data in;

input var1 $ var2 $;

cards;

aa x

aa y

aa z

bb t

bb y

cc .

cc .

cc .

;

proc sort data = in;by var1;

data temp; 

    set in;

    by var1;

    retain number 0;

    if first.var1 then number++ 1;retain number;

run;

I hope it helps!

Good luck.

Anca.

Shayan2012
Quartz | Level 8

Thanks a lot, Anca. Thats perfect. I was not familiar with retain Smiley Happy.

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 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
  • 2 replies
  • 2796 views
  • 1 like
  • 2 in conversation