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

hi,all

I have a category variable "class" ,I want to create a new variable "NO" which number ariable "class" ,the result as follows:

11.png

Thanks a lot!

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

This would only appear in the log if you did not have your By Statement, which initializes the first. and last. variables. 

View solution in original post

4 REPLIES 4
PeterClemmensen
Tourmaline | Level 20
data have;
input Class Grades;
datalines;
1 367
1 363
1 302
2 349
2 332
2 311
2 311
3 357
3 343
;

data want;
    set have;
    by class;
    if first.Class then No=0;
    No+1;
run;
HannaZhang
Obsidian | Level 7

Actually there are some missing with the variable "class" ,so I tried like follows,but the log

notes that variable first.class uninitialized.Any  solution? thanks

data want;
    set have;
    by class;
    if  Class^=. and  first.Class then No=0;
    No+1;
run;
PeterClemmensen
Tourmaline | Level 20

This would only appear in the log if you did not have your By Statement, which initializes the first. and last. variables. 

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!

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
  • 4 replies
  • 993 views
  • 0 likes
  • 2 in conversation