BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
sivastat08
Pyrite | Level 9

 

i want to create new column whereever missing is after that it should start give number like sequence123.123.123.

 

below is my data ihave tried but i not getting the exact one.please help me,

 

data new;
input have ;
datalines;

2
1
9
.
1
2
.
5
1
2
.
9
7
5
;

 

PROC SQL;
CREATE TABLE WORK.QUERY_FOR_NEW AS
SELECT t1.have,
/* getting*/
(case when t1.have = . then . else monotonic() end) AS getting
FROM WORK.NEW t1;
QUIT;

 

 

havegettingWant
.. 
211
122
933
.. 
141
252
.. 
561
172
283
.. 
991
7102
5113
1 ACCEPTED SOLUTION

Accepted Solutions
Jim_G
Pyrite | Level 9

Try adding this code to your first data step.

 

retain want 0;

if have=. then want=.;

else; want+1;

 

Jim

View solution in original post

5 REPLIES 5
Jim_G
Pyrite | Level 9

Try adding this code to your first data step.

 

retain want 0;

if have=. then want=.;

else; want+1;

 

Jim

sivastat08
Pyrite | Level 9
Hi Sir ,thanks for the quick answer.
Jim_G
Pyrite | Level 9
data new;
retain want 0;

input have;
if have=. then do; want=.; end;
else want+1;


datalines;

2
1
9
.
1
2
.
5
1
2
.
9
7
5
;

proc print; run;
sivastat08
Pyrite | Level 9
thanks for the answer sir. this code is working. thank you sir.
sivastat08
Pyrite | Level 9

i tried above code 

 

Data New1;
set new;
retain want 0;
if have=. then want=.;
want+1;
run;

 

i got wherever missing(.) its retained as 1 so tried instead of missing(.) as (-1) its working fine.

 

Data New1;
set new;
retain want 0;
if have=. then want= -1;
want+1;
run;

 

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

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
  • 5 replies
  • 746 views
  • 3 likes
  • 2 in conversation