BookmarkSubscribeRSS Feed
GS2
Obsidian | Level 7 GS2
Obsidian | Level 7

Using SAS 9.4

 

This will be a long post so I am sorry but I am interested to know: 1. if what I am asking is possible and 2. if possible, if someone can point me in the write direction or provide some literature

 

I am creating a compliance report by Month and Year that looks like the following:

 

 

MAY 2018

Complete

157

Partial

217

Complete & Partial

 (64.6%)

No Response

 (35.4%)

*newly:

 

X (#)

-

Revised (#)

2

Conversion (#)

-

Declined (#)

1

Total eligible for compliance**

579

Had Visit

(52.2%)

Breakdown of “Partial”:

(% Complete)

 

1

52.5%

2

44.2%

3

83.4%

4

82.5%

5

64.1%

6

35.0%

7

75.6%

8

73.7%

 

This report is complete for 3+ years and takes some time to fill out. The data I have indicates month and year with the following variables (sx_month sx_year).

 

1. The first 2 rows (not including the date at the top) are responses from variable A and are labeled in the variable as reported "Complete", "Partial"

2. The next 2 rows are the percents from the 2 responses of variable B and are labeled as they are in the variable "Complete & Partial", "No Response"

3. Rows 6-9 comes from variable A but may not always be present

4. Row 10 is the cummulative frequency of variable C

5. Row 11 is the percent of 1/2 responses (labeled "Not Missing") to variable C

6. Each of the variables labeled 1-8 indicates a survey with responses of 'complete' or 'incomplete' and I want to put into the report only where it is 'complete'

 

All of this I would like completed by month and year as the table shows

 

So, my questions are:

1. if it is possible to put only specific information into a report by month to help streamline and save time filling out the report manually

2. If it is posisble, does anyone have any thoughts or literature on how to get started 

4 REPLIES 4
ballardw
Super User

An actual example of the data set will be needed to answer this question properly. Best is to provide a data step with a small number of records and enough variety to cover the cases of your data.

 

Instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the </> icon or attached as text to show exactly what you have and that we can test code against. The code box is important because the message windows on this forum will reformat text a may modify the generated code in a manner that will prevent the data step from running.

 

Excel or similar is NOT usable data. Many users here don't want to download Excel files because of virus potential, others have such things blocked by security software. Also if you give us Excel we have to create a SAS data set and due to the non-existent constraints on Excel data cells the result we end up with may not have variables of the same type (numeric or character) and even values.

 

I suspect that the data may need to be reshaped somewhat. It may also help if you provide a desired example for 2 months. I cannot tell from this example whether you are wanting a separate report document, a separate table or a single table with multiple months as column headings.

 

Personally, I am not going to "count rows" to determine content. So it would be a good idea to label the rows.

 

If you have managed to place such disparate values, "date?", counts, percents, cumulative counts into a single variable then you have possibly caused yourself a lot more work than needed and it may be easier to go back to the data used to create this.

 

Possible, almost certainly. I have a similar sort of report that breaks out details by geographic region not date.

However each of the "rows" is a separate variable so the formats, appearance, labels and such make sense.

Reeza
Super User
Very possible. First calculate all the statistics you need into separate tables.
Second combine tables into nice SAS table and display with PROC REPORT/PRINT.

Or design an Excel template that shows what you want and then link the output to a different worksheet that has the raw data. Then use SAS to update the rawdata periodically. This approach is harder because you have dynamic rows like requirement 3 (may not always be present).

So, first, start with a sample data set and start buidling your components.

If you require further help, especially if you need code, please post some example raw data that reflects your data structure. It does not have to be real data, feel free to make fake data but its much easier and you'll get better responses if you provide sample data.
GS2
Obsidian | Level 7 GS2
Obsidian | Level 7

So this is a small sample of how my data:

  sx_month sx_year tot_comp_faam tot_comp_aofas_pt tot_comp_aofas_md tot_comp_ffi_34 tot_comp_vr12 tot_comp_vas tot_comp_survey lvisitxrdate new_clinicdate compliance
  XX XXXX Missing All Complete Complete Missing All Missing All Complete Partial Missing Missing Partial
  XX XXXX Missing All Complete Complete Missing All Missing All Complete Partial Missing Missing Partial

 

That goes into this macro:

 

%macro report_freqs(datain=,date9var=);
title "&datain.";
data &datain; set &datain;
if compliance_final in('Complete','Partial') then compliance_final2 = 'Complete & Partial';
else if compliance_final = 'No Response' then compliance_final2 = 'No Response';
array compvars tot_comp_faam tot_comp_ffi_34 tot_comp_vr12 tot_comp_aofas_pt tot_comp_aofas_md tot_comp_vas tot_comp_survey lvisitxrdate;
array newcompvars[8] $ tot_comp_faam2 tot_comp_ffi_342 tot_comp_vr122 tot_comp_aofas_pt2 tot_comp_aofas_md2 tot_comp_vas2 tot_comp_survey2 lvisitxrdate2;
do i=1 to dim(compvars);
if compvars(i) in('Comp','Complete', 'Not Missing') then newcompvars(i) = 'Complete';
else if compvars(i) in('Missing All','Partial', 'Missing') then newcompvars(i) = 'Other';
else newcompvars(i) = 'ERROR';
end;
run;
proc freq data=&datain;
where dos <= "&date9var."d ;
table compliance_final / nocum nopercent;
run;
proc freq data=&datain;
where dos <= "&date9var."d and compliance_final in('Complete','No Response','Partial');
table compliance_final2;
run;
proc freq data=&datain;
where dos <= "&date9var."d and compliance_final in('Complete','No Response','Partial');
table new_clinicdate;
run;
proc freq data=&datain;
where dos <= "&date9var."d and compliance_final = 'Partial';
table (lvisitxrdate2 tot_comp_faam2 tot_comp_ffi_342 tot_comp_vr122 tot_comp_aofas_pt2 tot_comp_aofas_md2 tot_comp_vas2 tot_comp_survey2)*compliance_final /missing norow nopercent;
run;
title;
%mend report_freqs;

 

I then use the following code for each month and year combo:

 

%report_freqs(datain=aug17, date9var=01AUG2017)

%report_freqs(datain=sep17, date9var=01sep2017)

 ...

Which is then put into this report:

 

AUG 2017

SEPT 2017

Complete

59

72

Partial

200

214

Complete & Partial

 (50.6%)

 (55.2%)

No Response

 (49.4%)

 (44.8%)

*newly:

 

 

X (#)

10

1

Revised (#)

23

2

Conversion (#)

9

-

Declined (#)

-

-

Total eligible for compliance**

512

518

Had a Visit

(31.1%)

(35.5%)

Breakdown of “Partial”:

(% Complete)

 

 

X-ray

40.0%

44.9%

FAAM

32.5%

36.0%

FFI-R

64.5%

66.8%

VR-12

64.5%

66.4%

AOFAS - pt

63.5%

62.6%

AOFAS - md

43.0%

42.1%

VAS

70.0%

74.3%

Survey

53.5%

60.3%

 

I would love to be able to streamline this so that I am not having to type out each individual freq and percent into the table. Thank you

ballardw
Super User

Not even going to attempt to type in that stuff to create a data set to test code.

 

One clue to your problem is this bit right here:

%report_freqs(datain=aug17, date9var=01AUG2017)
%report_freqs(datain=sep17, date9var=01sep2017)

If you have values on the records, such as month and year, or an actual date value then unless your aug17 and sep17 data sets are very poorly constructed you should be able to combine the data sets and use the date value to create columns.

 

The second is that you have Proc freq generating output that sounds like you are manually reading things and then retyping. Proc FREQ will create output data sets.

Example follows. You should have the SASHELP.CLASS set installed.

ods output onewayfreqs=work.classfreq;
proc freq data=sashelp.class ;
   tables sex age;
run;

data work.cleanerfreq;
   set work.classfreq;
   length rowlabel $ 20;
   rowlabel=coalescec(sex, age);
run;

proc print data= work.cleanerfreq;
   var rowlabel frequency cumfrequency percent cumpercent;
run;

If you run one of those proc freqs with your data sorted by date (DOS??) and a format assigning the date display as a single month, such as MO

NYY7. Then you get a count per month in the output.

This uses a data set you likely have in your install:

 

proc sort data=sashelp.snacks
          out=work.snacks;
   by date;
run;

ods output onewayfreqs=work.dayssold;
proc freq data=work.snacks;
   by date;
   where qtysold>0; 
   format date monyy7.;
   tables product;
run;

proc print data=work.dayssold;
var date product frequency;
run;

The where statement selects records so that only the days with a product sale is processed for the Proc Freq. The group created by the assigned format is honored for counting and the frequency is the number of days of sales because the source data has one record per product/date

Or conversely a slightly more complex report

proc report data=work.snacks;
   columns product date,( qtysold=qtyn qtysold=qtysum);
   format date monyy7.;
   define product /group;
   define date/across;
   define qtyn/ analysis n 'Days with sales';
   define qtysum/ analysis sum 'Total sales';
run;

 

 

I suspect with actual data I could do a report using Proc Tabulate as well.although you really have to tell why some of your percentage values are in () and others aren't. Typically (xx%) is one way of indicating negative percentages but since Proc Freq won't create negative percentages I am confused.

 

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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