## BASE SAS

Solved
Occasional Contributor
Posts: 15

# BASE SAS

This is my data:

PS           Lat           Long        Slot       Dist

 abc 75.8233 26.2454 1 0 abc 75.4785 26.4589 1 38939 abc 75.5495 26.4679 1 31174.1 abc 75.4875 26.8997 2 0 abc 75.5649 26.7268 2 9896.03 abc 75.5666 26.8647 2 8883.29 xyz 75.4875 26.3842 1 0 xyz 75.4937 26.5877 1 5735.38 xyz 75.8473 26.3971 1 40164.2 xyz 75.7861 26.6884 2 0

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,

@draycut

Accepted Solutions
Solution
‎06-06-2017 02:40 AM
PROC Star
Posts: 1,209

## 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;``````

All Replies
Solution
‎06-06-2017 02:40 AM
PROC Star
Posts: 1,209

## 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
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

@draycut

PROC Star
Posts: 1,209

## 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: 1,209

## 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

Community Manager
Posts: 704

Hi

PROC Star
Posts: 1,209