This is my data:
PS Lat Long Slot Dist
abc | 75.8233 | 26.2454 | 1 | 0.00 |
abc | 75.4785 | 26.4589 | 1 | 38939.03 |
abc | 75.5495 | 26.4679 | 1 | 31174.08 |
abc | 75.4875 | 26.8997 | 2 | 0.00 |
abc | 75.5649 | 26.7268 | 2 | 9896.03 |
abc | 75.5666 | 26.8647 | 2 | 8883.29 |
xyz | 75.4875 | 26.3842 | 1 | 0.00 |
xyz | 75.4937 | 26.5877 | 1 | 5735.38 |
xyz | 75.8473 | 26.3971 | 1 | 40164.19 |
xyz | 75.7861 | 26.6884 | 2 | 0.00 |
Now I want to copy those values which have dist less than 10000 to a new dataset and also delete these values from the original dataset,
So please suggest me some solution,
Thnx in advance
Something like this?
data have;
input PS$ lat long slot Dist;
datalines;
abc 75.8233 26.2454 1 0.00
abc 75.4785 26.4589 1 38939.03
abc 75.5495 26.4679 1 31174.08
abc 75.4875 26.8997 2 0.00
abc 75.5649 26.7268 2 9896.03
abc 75.5666 26.8647 2 8883.29
xyz 75.4875 26.3842 1 0.00
xyz 75.4937 26.5877 1 5735.38
xyz 75.8473 26.3971 1 40164.19
xyz 75.7861 26.6884 2 0.00
;
data have less_than_10000;
set have;
if dist < 10000 then output less_than_10000;
else output have;
run;
Something like this?
data have;
input PS$ lat long slot Dist;
datalines;
abc 75.8233 26.2454 1 0.00
abc 75.4785 26.4589 1 38939.03
abc 75.5495 26.4679 1 31174.08
abc 75.4875 26.8997 2 0.00
abc 75.5649 26.7268 2 9896.03
abc 75.5666 26.8647 2 8883.29
xyz 75.4875 26.3842 1 0.00
xyz 75.4937 26.5877 1 5735.38
xyz 75.8473 26.3971 1 40164.19
xyz 75.7861 26.6884 2 0.00
;
data have less_than_10000;
set have;
if dist < 10000 then output less_than_10000;
else output have;
run;
I also want to add a new column named XYZ and give value 1 in the new dataset and -100 in the previous dataset,
Plz suggest me some solution
Thnx in advance
data have;
input PS$ lat long slot Dist;
datalines;
abc 75.8233 26.2454 1 0.00
abc 75.4785 26.4589 1 38939.03
abc 75.5495 26.4679 1 31174.08
abc 75.4875 26.8997 2 0.00
abc 75.5649 26.7268 2 9896.03
abc 75.5666 26.8647 2 8883.29
xyz 75.4875 26.3842 1 0.00
xyz 75.4937 26.5877 1 5735.38
xyz 75.8473 26.3971 1 40164.19
xyz 75.7861 26.6884 2 0.00
;
data have less_than_10000;
set have;
if dist < 10000 then do;
xyz = 1;
output less_than_10000;
end;
else do;
xyz = -100;
output have;
end;
run;
If u could please suggest me as to how to append instead of output at this statement
output less_than_10000;
@PeterClemmensen
Here is the code with the append procedure from the deleted thread @Himanshu007
data Dataset_1;
input PS$ lat long slot Dist xyz;
datalines;
abc 75.8233 26.2454 1 0 2
abc 75.4875 26.8997 2 0 2
xyz 75.4875 26.3842 1 0 2
xyz 75.7861 26.6884 2 0 2
;
data Dataset_2;
input PS$ lat long slot Dist xyz;
datalines;
abc 75.4785 26.4589 1 0.00 -100
abc 75.5495 26.4679 1 7929.25 -100
abc 75.5649 26.7268 2 0.00 -100
abc 75.5666 26.8647 2 3843.27 -100
xyz 75.4937 26.5877 1 0.00 -100
xyz 75.8473 26.3971 1 39820.47 -100
;
proc append base = Dataset_1 data = Dataset_2;
where Dist < 5000;
run;
Dont know why it is deleted 🙂
Hi draycut, Himanshu007,
The other thread got caught in the spam filter. I've "released" so it's now on the community but I'm going to delete because the solution is on this thread.
Best,
Anna
Great, @AnnaBrown, have a nice day
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.