After missing new column should start with sequence

Accepted Solution Solved
Reply
Contributor
Posts: 61
Accepted Solution

After missing new column should start with sequence

 

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

Accepted Solutions
Solution
‎09-25-2017 07:15 AM
Frequent Contributor
Posts: 99

Re: After missing new column should start with sequence

[ Edited ]
Posted in reply to sivastat08

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


All Replies
Solution
‎09-25-2017 07:15 AM
Frequent Contributor
Posts: 99

Re: After missing new column should start with sequence

[ Edited ]
Posted in reply to sivastat08

Try adding this code to your first data step.

 

retain want 0;

if have=. then want=.;

else; want+1;

 

Jim

Contributor
Posts: 61

Re: After missing new column should start with sequence

Hi Sir ,thanks for the quick answer.
Frequent Contributor
Posts: 99

Re: After missing new column should start with sequence

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;
Contributor
Posts: 61

Re: After missing new column should start with sequence

thanks for the answer sir. this code is working. thank you sir.
Contributor
Posts: 61

Re: After missing new column should start with sequence

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;

 

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 5 replies
  • 136 views
  • 3 likes
  • 2 in conversation