We can only see the fist two letters of the word Total in the output table.
Below is the code:
proc report data=Staffreport nowd
style(report)={just=l}
style(column)={just=c}
headline headskip;
length bgPHAAssignment $8;
by babydate;
column ('Homevisitng and BF Observation Success by PHA' (bgPHAAssignment('Homevisiting Success' c_S_Yes c_S_No Pct_S_Yes Pct_S_No Total_S))
('BF Observations' c_obsct_0 c_obsct_1 c_obsct_2 Pct_obsct_0 Pct_obsct_1 Pct_obsct_2 Total_obsct));
define bgPHAAssignment/display "PHA" style=[CELLWIDTH=100];
define c_S_Yes/display sum 'Yes' style=[CELLWIDTH=80];
define c_S_No/display sum 'No' style=[CELLWIDTH=80];
define Pct_S_Yes/display 'Percent Yes' style=[CELLWIDTH=115];
define Pct_S_No/display 'Percent No' style=[CELLWIDTH=110];
define Total_S/display sum 'Total';
define c_obsct_0/display sum 'No Obs' style=[CELLWIDTH=80];
define c_obsct_1/display sum '1 Obs' style=[CELLWIDTH=80];
define c_obsct_2/DISPLAY sum '2+ Obs' style=[CELLWIDTH=80];
define Pct_obsct_0/display '% No Obs' style=[CELLWIDTH=110];
define Pct_obsct_1/DISPLAY '% 1 Obs' style=[CELLWIDTH=100];
define Pct_obsct_2/DISPLAY '% 2+ Obs' style=[CELLWIDTH=100];
define Total_obsct/display sum 'Total';
RBREAK AFTER / SUMMARIZE ;
COMPUTE AFTER;
bgPHAAssignment = 'Total';
ENDCOMP;
run;
ODS PDF CLOSE;
title
Because you did not tell it how to convert the number into a character string.
compute dispname/ character length=13;
dispname=put(BABYDATE,monyy7.);
endcomp;
Hi: If you do a PROC CONTENTS on your data set, how wide (how many characters) is the bgPHAAssignment variable. My guess is that it is defined a character with a length of 2 or a formatted value of 2. Changing the CELLWIDTH will not change the internal storage size of the variable. Here's one way of doing what you want to do using a COMPUTED column:
Cynthia
I tried that but the cell is now blank:
proc report data=Staffreport nowd
style(report)={just=l}
style(column)={just=c}
headline headskip;
length bgPHAAssignment $8;
by babydate;
column ('Homevisitng and BF Observation Success by PHA' (bgPHAAssignment('Homevisiting Success' c_S_Yes c_S_No Pct_S_Yes Pct_S_No Total_S))
('BF Observations' c_obsct_0 c_obsct_1 c_obsct_2 Pct_obsct_0 Pct_obsct_1 Pct_obsct_2 Total_obsct));
define bgPHAAssignment/display "PHA" style=[CELLWIDTH=100];
define c_S_Yes/display sum 'Yes' style=[CELLWIDTH=80];
define c_S_No/display sum 'No' style=[CELLWIDTH=80];
define Pct_S_Yes/display 'Percent Yes' style=[CELLWIDTH=115];
define Pct_S_No/display 'Percent No' style=[CELLWIDTH=110];
define Total_S/display sum 'Total';
define c_obsct_0/display sum 'No Obs' style=[CELLWIDTH=80];
define c_obsct_1/display sum '1 Obs' style=[CELLWIDTH=80];
define c_obsct_2/DISPLAY sum '2+ Obs' style=[CELLWIDTH=80];
define Pct_obsct_0/display '% No Obs' style=[CELLWIDTH=110];
define Pct_obsct_1/DISPLAY '% 1 Obs' style=[CELLWIDTH=100];
define Pct_obsct_2/DISPLAY '% 2+ Obs' style=[CELLWIDTH=100];
define Total_obsct/display sum 'Total';
define dispname/ computed 'bgPHAAssignment';
RBREAK AFTER / SUMMARIZE ;
COMPUTE dispname/ character length=10;
dispname = bgPHAAssignment;
endcomp;
compute after;
dispname = 'Total';
ENDCOMP;
run;
Thanks. I think I am getting closer. Instead it created a new column with total at the bottom.
proc report data=bororeport_Rearranged nowd
style(report)={just=l}
style(column)={just=c}
headline headskip;
column ('Bronx - Homevisitng and BF Observation Success' dispname(BABYDATE('Homevisiting Success' count_Yes pct_row_Yes count_No pct_row_No Total_S))
('BF Observations' count_0 pct_row_0 count_1 pct_row_1 count_2 pct_row_2 Total_obs));
define BABYDATE/display "Baby's DOB" style=[CELLWIDTH=120];
define count_Yes/display sum 'Yes' style=[CELLWIDTH=60];
define pct_row_Yes/display 'Percent Yes' style=[CELLWIDTH=115];
define count_No/display sum 'No' style=[CELLWIDTH=60];
define pct_row_No/display 'Percent No' style=[CELLWIDTH=110];
define Total_S/display sum 'Total' style=[CELLWIDTH=60];
define count_0/display sum 'No Obs' style=[CELLWIDTH=80];
define pct_row_0/display '% No Obs' style=[CELLWIDTH=100];
define count_1/display sum '1 Obs' style=[CELLWIDTH=70];
define pct_row_1/DISPLAY '% 1 Obs' style=[CELLWIDTH=100];
define count_2/DISPLAY sum '2+ Obs' style=[CELLWIDTH=80];
define pct_row_2/DISPLAY '% 2+ Obs' style=[CELLWIDTH=100];
define Total_obs/display sum 'Total' style=[CELLWIDTH=60];
define dispname/computed "BABYDATE";
RBREAK AFTER / SUMMARIZE ;
compute dispname/ character length=6;
dispname="BABYDATE";
endcomp;
COMPUTE AFTER;
dispname = 'Total';
ENDCOMP;
run;
Hi:
DISPNAME has to be wide enough to display ALL the characters in BABYDATE (8 characters) and the 5 characters in the word Total. I would expect that you are NOT seeing the entire word BABYDATE when you do this report. (Sorry, your PDF wouldn't open for me so that is just a guess.)
Without data to experiment with or seeing all of your report in a screen shot, I'm not sure what you mean by your statement that " Instead it created a new column with total at the bottom. " That is exactly what dispname is supposed to do. Here's a modified version of my program and the output:
In my example see how NAME is the first item on the COLUMN statement. If I want the value of NAME on every row to be assigned to the DISPNAME column, then NAME has to be to the left of DISPNAME on the COLUMN statement. You will see this in both Example 2 and Example 3. Also note in #2 how you don't see NAME on the report because the DEFINE for NAME uses the NOPRINT option. But, in both #2 and #3 example, in the COMPUTE block for DISPNAME, I assign the value of NAME on THAT row to be the value of DISPNAME on that row. In your recent example, you assign the fixed string "BABYDATE" to the DISPNAME column -- that's going to give you a fixed string with a length of 6 on every row, which probably is NOT what you want.
In Example #3, notice how I have removed the NOPRINT option from the DEFINE for NAME and I have put DispName as the column header label for the DISPNAME column. So in #3, you should see the same value for student name in the first 2 columns. What NOPRINT does in #2 is allow me to use the value of NAME, but hide it on the report.
Cynthia
thank you so much! I see my mistake. I had not used "noprint" - Baby's DOB was showing as two columns.
I now have a Baby's DOB column with Total at the bottom. The problem now is that the date is no longer showing in the MonYYYY format. It's just numeric.
I hope that you can now see the attachment.
proc report data=bororeport_Rearranged nowd
style(report)={just=l}
style(column)={just=c}
headline headskip;
column ('Bronx - Homevisitng and BF Observation Success'(BABYDATE dispname('Homevisiting Success' count_Yes pct_row_Yes count_No pct_row_No Total_S))
('BF Observations' count_0 pct_row_0 count_1 pct_row_1 count_2 pct_row_2 Total_obs));
define BABYDATE/display "Baby's DOB" style=[CELLWIDTH=120] noprint;
define count_Yes/display sum 'Yes' style=[CELLWIDTH=60];
define pct_row_Yes/display 'Percent Yes' style=[CELLWIDTH=115];
define count_No/display sum 'No' style=[CELLWIDTH=60];
define pct_row_No/display 'Percent No' style=[CELLWIDTH=110];
define Total_S/display sum 'Total' style=[CELLWIDTH=60];
define count_0/display sum 'No Obs' style=[CELLWIDTH=80];
define pct_row_0/display '% No Obs' style=[CELLWIDTH=100];
define count_1/display sum '1 Obs' style=[CELLWIDTH=70];
define pct_row_1/DISPLAY '% 1 Obs' style=[CELLWIDTH=100];
define count_2/DISPLAY sum '2+ Obs' style=[CELLWIDTH=80];
define pct_row_2/DISPLAY '% 2+ Obs' style=[CELLWIDTH=100];
define Total_obs/display sum 'Total' style=[CELLWIDTH=60];
define dispname/computed "Baby's DOB";
RBREAK AFTER / SUMMARIZE ;
compute dispname/ character length=13;
dispname=BABYDATE;
endcomp;
COMPUTE AFTER;
dispname = 'Total';
ENDCOMP;
run;
I used format=MONYY7. but the dates are all showing as JAN1960. I am not sure how to fix it.
column ('Bronx - Homevisitng and BF Observation Success'(BABYDATE dispname('Homevisiting Success' count_Yes pct_row_Yes count_No pct_row_No Total_S))
('BF Observations' count_0 pct_row_0 count_1 pct_row_1 count_2 pct_row_2 Total_obs));
define BABYDATE/display "Baby's DOB" style=[CELLWIDTH=120] noprint;
define count_Yes/display sum 'Yes' style=[CELLWIDTH=60];
define pct_row_Yes/display 'Percent Yes' style=[CELLWIDTH=115];
define count_No/display sum 'No' style=[CELLWIDTH=60];
define pct_row_No/display 'Percent No' style=[CELLWIDTH=110];
define Total_S/display sum 'Total' style=[CELLWIDTH=60];
define count_0/display sum 'No Obs' style=[CELLWIDTH=80];
define pct_row_0/display '% No Obs' style=[CELLWIDTH=100];
define count_1/display sum '1 Obs' style=[CELLWIDTH=70];
define pct_row_1/DISPLAY '% 1 Obs' style=[CELLWIDTH=100];
define count_2/DISPLAY sum '2+ Obs' style=[CELLWIDTH=80];
define pct_row_2/DISPLAY '% 2+ Obs' style=[CELLWIDTH=100];
define Total_obs/display sum 'Total' style=[CELLWIDTH=60];
define dispname/computed "Baby's DOB" format=MONYY7.;
RBREAK AFTER / SUMMARIZE ;
compute dispname/ character length=13;
dispname=BABYDATE;
endcomp;
COMPUTE AFTER;
dispname = 'Total';
Because you did not tell it how to convert the number into a character string.
compute dispname/ character length=13;
dispname=put(BABYDATE,monyy7.);
endcomp;
I tried that, but the date are all JAN1960 and the "Total" is no longer showing.
I used another dataset that doesn't use date. The same thing happened my letters became numbers.
please see attached
@bn820 wrote:
I tried that, but the date are all JAN1960 and the "Total" is no longer showing.
I used another dataset that doesn't use date. The same thing happened my letters became numbers.
please see attached
Post code as TEXT using the SAS "running man" icon. Post LOG lines as text using the Insert code "< / >" icon. Post pictures directly using the "camera" icon.
If the source variable NUMERIC or CHARACTER? If numeric does it contain date values? Or something else.
Play around and figure it out for yourself. Here is an example that starts with a DATE, a STRING, and a general NUMBER and for each of them computes both a numeric and a character version.
data test;
date=today();
format date date9.;
string = '23AUG2023';
number = 10;
run;
proc report data=test;
column date date2 date3 string string2 string3 number number2 number3 ;
define date / display ;
define number / display ;
define date2 / computed ;
define date3 / computed format=monyy7. ;
define string2 / computed format=mmddyy10.;
define string3 / computed;
define number2 / computed;
define number3 / computed;
compute date2 / character length=10 ;
date2 = put(date,yymmdd10.);
endcomp;
compute date3 ;
date3=date;
endcomp;
compute string2 ;
string2 = input(string,date9.);
endcomp;
compute string3 / character length=7 ;
string3 = substr(string,3);
endcomp;
compute number2 ;
number2 = number**2 ;
endcomp;
compute number3 / character length=5 ;
number3=put(number,z5.);
endcomp;
run;
It worked.
I had to apply it to the dataset, not the proc report.
data bororeport_Rearranged3;
set bororeport_Rearranged3;
babydate_character=put(babydate,$monyy7.);
run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.
Select SAS Training centers are offering in-person courses. View upcoming courses for: