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

This is my data:

PS           Lat           Long        Slot       Dist

abc75.823326.245410.00
abc75.478526.4589138939.03
abc75.549526.4679131174.08
abc75.487526.899720.00
abc75.564926.726829896.03
abc75.566626.864728883.29
xyz75.487526.384210.00
xyz75.493726.587715735.38
xyz75.847326.3971140164.19
xyz75.786126.688420.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

@PeterClemmensen

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

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;

View solution in original post

10 REPLIES 10
PeterClemmensen
Tourmaline | Level 20

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;
Himanshu007
Obsidian | Level 7
Exactly, thnx a lot
Himanshu007
Obsidian | Level 7
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
Himanshu007
Obsidian | Level 7

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

@PeterClemmensen

PeterClemmensen
Tourmaline | Level 20
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;
Himanshu007
Obsidian | Level 7
It works,
Thnx a lot
Himanshu007
Obsidian | Level 7

If u could please suggest me as to how to append instead of output at this statement
output less_than_10000;
@PeterClemmensen

PeterClemmensen
Tourmaline | Level 20

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 🙂

 

AnnaBrown
Community Manager

Hi 

 

 

PeterClemmensen
Tourmaline | Level 20

Great, @AnnaBrown, have a nice day

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 10 replies
  • 2111 views
  • 4 likes
  • 3 in conversation