BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
BrahmanandaRao
Lapis Lazuli | Level 10
data dss;
set sashelp.class;
run;



data ddd;
set dss;
if age = _n_  then age= 20 ;
proc print;
run;

I want replace all age values with 20 

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26
data dss;
    set sashelp.class;
    age=20;
run;
--
Paige Miller

View solution in original post

2 REPLIES 2
PaigeMiller
Diamond | Level 26
data dss;
    set sashelp.class;
    age=20;
run;
--
Paige Miller
AMSAS
SAS Super FREQ

 

To understand what your code is doing, I recommend you look at the Automatic Variables documentation.

_N_ is initially set to 1. Each time the DATA step loops past the DATA statement, the variable _N_ increments by 1. The value of _N_ represents the number of times the DATA step has iterated.

 

As your IF statement is comparing _n_ with the variable age (sashelp.class) then you probably only set a single observation to 20. Observation #11 is Joyce and her age is 11, as _n_ would be 11 and age is 11 then you set age to 20 for that single observation.


 

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 770 views
  • 0 likes
  • 3 in conversation