BookmarkSubscribeRSS Feed
souji
Obsidian | Level 7

 

 In SAS Prep guide, how it defined id=1147 is age 65 (it could be some # in age)..please explain

 

data work.clean_data;

set cert.pats;

gender=upcase(Gender);

if Gender='G' then Gender='M';

if id=1147 then age=65;

else if id=5277 then age=75;

run;

proc print data=work.clean_data;

run;

3 REPLIES 3
Patrick
Opal | Level 21

The value of ID comes from your source table cert.pats.

The code then has a condition which tests the value of ID (if id=1147). If the value of ID coming from your source table is 1147 then the condition becomes true and the bit after THEN gets executed. So here a value of 65 gets assigned to variable age overwriting whatever value age had before. The result gets at the end of the data step written to output table work.clean_data.

ed_sas_member
Meteorite | Level 14

Hi @souji 

 

Please compare the two datasets below (on the left, the initial dataset cert.pats; on the right the new one that has been created):

  1. Firstly, we ensure that all gender values are in upper case, because we want to replace all "G" by "M". If there was a value like "g", the condition won't apply.
  2. Secondly, for the specific ID value 1147 (age = 116), we want to replace the age by 65 (which is more plausible). The same for id=5277 (age 202 replaced by 75).

cert.patscert.patswork.clean_datawork.clean_data

 

souji
Obsidian | Level 7

Thank You for the explanation , but I can give the other number ( like 80) instead of 65

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
  • 3 replies
  • 359 views
  • 1 like
  • 3 in conversation