DATA Step, Macro, Functions and more

BASE SAS

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 15
Accepted Solution

BASE SAS

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

@draycut


Accepted Solutions
Solution
‎06-06-2017 02:40 AM
PROC Star
Posts: 554

Re: BASE SAS

[ Edited ]

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


All Replies
Solution
‎06-06-2017 02:40 AM
PROC Star
Posts: 554

Re: BASE SAS

[ Edited ]

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

Re: BASE SAS

Exactly, thnx a lot
Occasional Contributor
Posts: 15

Re: BASE SAS

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
Occasional Contributor
Posts: 15

Re: BASE SAS

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

@draycut

PROC Star
Posts: 554

Re: BASE SAS

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

Re: BASE SAS

It works,
Thnx a lot
Occasional Contributor
Posts: 15

Re: BASE SAS

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

PROC Star
Posts: 554

Re: BASE SAS

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 Smiley Happy

 

Community Manager
Posts: 486

Re: BASE SAS

Hi 

 

 

PROC Star
Posts: 554

Re: BASE SAS

Great, @AnnaBrown, have a nice day

☑ This topic is solved.

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

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