Hello, I am writing a program that creates, manipulates, and later combines datasets from numerous CSV files that are all structured differently. I have a program I wrote last year that works. But, since I will be updating the dataset each year as new data is released, I would like to refine the code to make it smaller and more efficient. The image below is an example of the raw data I am working with in the data step below. Below is a copy of the code I want to work (emphasis on want). %macro age_gender(year,n);
data age_gender&year;
infile "&path\Table 1 - Unduplicated Users by Age and Gender &year..csv" firstobs=6 obs=&n dsd;
input Site :$35. Gender $ AgeUnd_15 Age15_17 Age18_19 Age20_24 Age25_29 Age30_34 Age35_39 Age40_44 AgeOver_44 Total;
year=&year;
array varname {*} age: total;
do i=1 to dim(varname);
if propcase(gender)='Female' then Fem&varname{i} = varname{i};
else if propcase(gender)='Male' then Male&varname{i} = varname{i};
else if propcase(gender)='Unknown' then Unk&varname{i} = varname{i};
else if propcase(gender)='Total' then Tot&varname{i} = varname{i};
else if gender='--- Null' then Null&varname{i} = varname{i};
end;
drop AgeUnd_15 Age15_17 Age18_19 Age20_24 Age25_29 Age30_34 Age35_39 Age40_44 AgeOver_44 Total;
run;
%mend;
%age_gender(2015,210);
%age_gender(2016,207);
%age_gender(2017,205); As it is, SAS is not recognizing my use of prefix and array reference to rename variables to categorize by gender. I would greatly appreciate any insights as to how I may correct the syntax for the program I am trying to write, or if there is a better way to do this. Thanks, Ted
... View more