Data ds;
Cards;
1
2
3
4
5
6
;
Run;
How to add new observation in 3.5 in after 3
Method 1:
Data ds;
input x;
Cards;
1
2
3
3.5
4
5
6
;
run;
Method 2:
Data ds;
input x;
Cards;
1
2
3
4
5
6
;
data ds;
done=0;
do until(done);
set ds end=done;
output;
end;
x=3.5; output;
drop done;
stop;
run;
proc sort; by x;
run;
Output like that
1
2
3
3.5
4
5
6
Like that
Please test your code before posting it, and use a descriptive subject line. I edited your subject line
@Saleem wrote:
Data ds;
Cards;
1
2
3
4
5
6
;
Run;
How to add new observation in 3.5 in after 3
.
@Saleem wrote:
Data ds;
Cards;
1
2
3
4
5
6
;
Run;
How to add new observation in 3.5 in after 3
You should provide a generic rule. Is this going to happen every time the value 3 appears or just once? Is the value supposed to be the mean of the current and the following value? Are any other variables going to be involved? If so, where do their values come from (the record with the 3 or somewhere else).
One way is to have a data set with just the value of 3.5, append the sets and sort.
Your data step does not run as expected because there is no INPUT and so no variable is created. I take the liberty of providing a variable.
Or
Data ds; input value; Cards; 1 2 3 4 5 6 ; Run; data want; set ds; output; if value=3 then do; value=3.5; output; end; run;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.