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
data dss;
set sashelp.class;
age=20;
run;
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.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
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!
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.
Ready to level-up your skills? Choose your own adventure.