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-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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