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

I am attempting to use the following code to generate separate pdf documents for each of the 85 districts. However, the code is outputting 85 pdf documents each containing 85 tables for the distinct districts. How might I be able to change the code to accomplish this? Or is there an altogether easier approach? Thank you for your help.

 

%let districtcode=;
%let inputfile = work.Ind_14_Exiters ; *from previous step;
%let outfile = Ind14_Report;
%let FinalOutFileTest = "W:\SASDEV\OSES\Indicator\&districtcode..pdf";


data &outfile;
set &inputfile(rename=(districtid=districtcode)); ;


* if testtype = 'SCREADY' or testtype = 'NCSC';
* DISTRICT = "";
* retain ID Grade_Level Performance_Level_HSASSESS_ELA Performance_Level_HSASSESS_MTH SCHOOLID SCPASS_PerformanceLevel_ELA SCPASS_PerformanceLevel_Math STUDENTID Test_Date Year_ID STUDENT_NUMBER2 LAST_NAME2 FIRST_NAME2 MIDDLE_NAME2 GenerationCode districtcode StateID DistrictCode3;

* (RENAME =());

length new_districtcode $ 4;
new_districtcode=districtcode;
new_districtcode = translate(right(new_districtcode),'0',' ');
drop districtcode;
rename new_districtcode=districtcode;


Pad000 = '000';
length DistrictCode3 $ 7.;
DistrictCode3 = cats(districtcode,Pad000);
* %let DistrictCode3 = DistrictCode3;
drop Pad000;
* drop DistrictCode3;
/*
nTest_Date = put(Test_Date,mmddyy10.);
drop Test_Date;
rename nTest_Date = Test_Date;
*/
run;


PROC FREQ data= &outfile; TABLES districtcode*DistrictCode3/LIST MISSING OUT=WRITEDISTRICTS;run;
DATA _NULL_;
*LENGTH TEMP$213;

FILE'W:\SASDEV\OSES\macro_calls_dont_delete.sas';

set writedistricts;

TEMP=COMPBL('%processdistrict('||districtcode||','||DistrictCode3||')');
put TEMP;
RUN;


PROC SORT DATA=&outfile;
BY
districtcode
;

RUN;



%MACRO PROCESSDISTRICT(districtcode,DistrictCode3);


ODS PDF FILE="W:\SASDEV\OSES\Indicator\&districtcode..pdf" STYLE=Pearl;

TITLE;
TITLE1 "Post-Secondary Outcomes Survey Results";
FOOTNOTE;
FOOTNOTE1 "Competitive Employment requires that all of the following criteria be met: (1) worked at least 90 days; (2) Earned minimum wage; (3) worked at least 20 hours per week.";

PROC TABULATE
DATA=&outfile;
VAR Exiters "Survey Respondents"n "Higher Education Only (College)"n "Higher Ed and Competitive"n "Competitive Employment Only"n "Vocational/Technical School Only"n "Voc and Competitively Employed"n "Other School or Employment"n
"No Work/No Education"n;
CLASS ReportingDisability /
ORDER=UNFORMATTED MISSING;
CLASS District_Renamed /
ORDER=UNFORMATTED MISSING;
TABLE /* Page Dimension */
District_Renamed,
/* Row Dimension */
ReportingDisability*(
Exiters={STYLE={BACKGROUND=#FFFF00}}*{STYLE={BACKGROUND=#FFFF00}}
'Survey Respondents'n={STYLE={BACKGROUND=#FFFF00}}*{STYLE={BACKGROUND=#FFFF00}}
'Higher Education Only (College)'n
'Higher Ed and Competitive'n
'Competitive Employment Only'n
'Vocational/Technical School Only'n
'Voc and Competitively Employed'n
'No Work/No Education'n
'Other School or Employment'n),
/* Column Dimension */
Max={LABEL="Total"}*F=BEST3. ;
;

RUN;
/* -------------------------------------------------------------------
End of task code
------------------------------------------------------------------- */
RUN; QUIT;
TITLE; FOOTNOTE;

ODS PDF CLOSE;



%MEND PROCESSDISTRICT;


FILENAME RUNTHIS 'W:\SASDEV\OSES\macro_calls_dont_delete.sas';
%INCLUDE RUNTHIS;
RUN;

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

If you are wanting one document for each of the district codes it looks like you need to add a WHERE clause to the Proc tabulate syntax to select the district of interest only.

 

You are using some many different "district" variables I am not sure which one you need but it would likely look something like:

 

Where district = &districtcode. ;  if the district variable is numeric or

Where district = "&districtcode." ; if the district variable is character.

 

The "district" variable would be the appropriate one to filter data with.

View solution in original post

2 REPLIES 2
ballardw
Super User

If you are wanting one document for each of the district codes it looks like you need to add a WHERE clause to the Proc tabulate syntax to select the district of interest only.

 

You are using some many different "district" variables I am not sure which one you need but it would likely look something like:

 

Where district = &districtcode. ;  if the district variable is numeric or

Where district = "&districtcode." ; if the district variable is character.

 

The "district" variable would be the appropriate one to filter data with.

PhillipSherlock
Obsidian | Level 7

Beautiful! Thank you!

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1193 views
  • 0 likes
  • 2 in conversation