| X | A | B | C |
| X1 | 4 | 5 | 6 |
| X2 | 10 | 11 | 13 |
| X3 | 5 | 9 | 10 |
| FirstQtr | 1 | 8 | 5 |
| LTV | 6 | 4 | 2 |
I want to pickup the last value of column 'C' (Marked in Color). and assign it to variable New_var.
Desired O/p
New_var=2 ;
I need it in dataset.
Use the END= data set option:
DATA two ;
SET one END=last ;
IF last THEN DO ;
New_Var=C ;
END ;
RUN ;
data have;
input X $ A B C;
cards;
X1 4 5 6
X2 10 11 13
X3 5 9 10
FirstQtr 1 8 5
LTV 6 4 2
;
data want;
set have;
if _n_=1 then set have(keep=c rename=c=new_var) point=nobs nobs=nobs;
run;
data want;
set have (keep=c) nobs=nobs point=nobs;
rename c=new_var;
output;
stop;
run;
Reads only the last observation, and keeps variable c under a new name.
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!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.