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

Hi,

Can anyone tell me how can i delete all the Geography from rows which are having zero value while summing for that geography. There are around 10,000 different Geographies in my dataset.

I have attached the excel file for reference.

1 ACCEPTED SOLUTION

Accepted Solutions
TarunKumar
Pyrite | Level 9
data have; input Geography$8. Variable_Value; datalines; Geo00001 1 Geo00001 3 Geo00001 4 Geo00001 5 Geo00002 0 Geo00002 0 Geo00002 0 Geo00002 0 Geo00003 5 Geo00003 0 Geo00003 0 Geo00003 7 Geo00003 0 Geo00003 2 Geo00004 0 Geo00004 0 Geo00004 0 Geo00004 0 Geo00004 0 run; proc sort data=have;by Geography descending Variable_Value;run; data want ; set have; by Geography ; if first.Geography then t = 0; t+Variable_Value; if t ne 0; drop t; run;

View solution in original post

3 REPLIES 3
PeterClemmensen
Tourmaline | Level 20

Something like this?

 

data have;
input Geography$ Variable_Value;
datalines;
Geo00001 1
Geo00001 3
Geo00001 4
Geo00001 5
Geo00002 0
Geo00002 0
Geo00002 0
Geo00002 0
Geo00003 5
Geo00003 0
Geo00003 0
Geo00003 7
Geo00003 0
Geo00003 2
Geo00004 0
Geo00004 0
Geo00004 0
Geo00004 0
Geo00004 0
;

proc sort data=have;
	by Geography;
run;

/* Data set approach */
data want;
	set have(where=(Variable_Value ne 0));
	by Geography;
	if first.Geography then sum=0;
	else sum+Variable_Value;
	retain sum;
	if last.Geography;
run;
TarunKumar
Pyrite | Level 9
data have; input Geography$8. Variable_Value; datalines; Geo00001 1 Geo00001 3 Geo00001 4 Geo00001 5 Geo00002 0 Geo00002 0 Geo00002 0 Geo00002 0 Geo00003 5 Geo00003 0 Geo00003 0 Geo00003 7 Geo00003 0 Geo00003 2 Geo00004 0 Geo00004 0 Geo00004 0 Geo00004 0 Geo00004 0 run; proc sort data=have;by Geography descending Variable_Value;run; data want ; set have; by Geography ; if first.Geography then t = 0; t+Variable_Value; if t ne 0; drop t; run;
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Post test data in the form of a datastep, within the body of the post, using the {i} code window.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 872 views
  • 1 like
  • 4 in conversation