## array

Regular Contributor
Posts: 206

# array

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;

PROC Star
Posts: 8,150

## Re: array

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

Regular Contributor
Posts: 206

Thanks!
Super User
Posts: 13,358

## Re: array

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.

Regular Contributor
Posts: 206

## Re: array

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!
Discussion stats
• 4 replies
• 124 views
• 0 likes
• 3 in conversation