BookmarkSubscribeRSS Feed
Cho8
Calcite | Level 5
XBC
X1456
X2101113
X35910
FirstQtr185
LTV642

 

 

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.

3 REPLIES 3
GBL__
Quartz | Level 8

Use the END= data set option:

 

DATA two ;

    SET one END=last ;

    IF last THEN DO ;

        New_Var=C ;

    END ;

RUN ;

novinosrin
Tourmaline | Level 20

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;
Kurt_Bremser
Super User
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.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 646 views
  • 1 like
  • 4 in conversation