BookmarkSubscribeRSS Feed
jcis7
Pyrite | Level 9

 

Hi,

 

I have the data below.

Where population is >=15 and <=25, if there are any pct values >=96, I need to replace the pct value with a 96+ and the associated number value with a --.

 

Where the population is >=26 and <=99, if there are any pct values >=97, I need to replace the pct value with a 97+ and the associated number value with a --.

 

Where the population is >=100, if there are any pct values >=99, I need to replace the pct value with a 99+ and the associated number value with a --.

 

 

 

 

I have the SAS code below.

 

A few questions: 

1) Did I do this right?

2) When I export to MS Excel and use find/replace (i.e, find -1 and replace with --), why do I come up with 4 more values of -1 than the combined count of -2, -3, and -4?  I tried filtering in Excel just for the -1 values to see if the 4 extra -1's didn't have matching -2 or -3 or -4 but I couldn't find any of the extra -1's. 

a) Therefore, how do I find any -1 in the SAS dataset (which is only in the num column) that doesn't have a matching -2 or -3 or -4 value? 

b) Why do I have 4 extra -1's?

c) How can I double check I am getting what I want to get?

 

Thanks!

 

 

 

data have;

input buildingname & $20. population numvax1 pctvax1 numvax2 pctvax2   numvax3 pctvax3   buildingtype $;

cards;

happy days                100        99   99     96   96       100   100       private

learning tree               20         18   90     18   90       19      95       public

bean stalk                 50         50 100     50 100       50   100       public

;

 

proc format;

value pct

-2="96+"

-3="97+"

-4="99+";

value nm

-1="--";

run;

data want;

set have;

if population >=15;;

array pcts{*} pct_:;

array nums{*} num_:;

do i=1 to dim(pcts);

if 15=<population<=25 and pcts{i}>=96then nums{i}=-1;

if 15=<population<=25 and pcts{i}>=96 then pcts{i}=-2;

 

if 26=<population<=99 and pcts{i}>=97 then nums{i}=-1;

if 26=<population<=99 and pcts{i}>=97 then pcts{i}=-3;

 

if population>=100 and pcts{i}>=99 then nums{i}=-1;

if population>=100 and pcts{i}>=99 then pcts{i}=-4;

end;

format pct_: pct.;

format num_: nm.;

run;

 

4 REPLIES 4
art297
Opal | Level 21

There are no underscores in your num and pct variables. Rather than:

array pcts{*} pct_:;
array nums{*} num_:;

I think you want:

array pcts{*} pct:;
array nums{*} num:;

If your problem is more than that, you would have to show the resulting table that you want.

 

Art, CEO, AnalystFinder.com

 

jcis7
Pyrite | Level 9
Thanks!
ballardw
Super User

I tend to not replace variables when doing this type of recoding as it makes answering your questions about what happened when I recode hard to tell.

 

You would have to provide both the start and end data for the Excel you created. And since the code you post, per @art297's comment would not run unless you have variables that you did not include in your example data you would have to show either the data or the actual code.

jcis7
Pyrite | Level 9
OK. I am going the route of creating a new set of character variables so I can double check the old with the new. Thanks!

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
  • 4 replies
  • 674 views
  • 0 likes
  • 3 in conversation