Hi,
I have a dataset like as below.
Description | type | count |
---|---|---|
Desc1 | type1 | 3 |
Desc1 | type2 | 4 |
Desc1 | type3 | 5 |
Desc2 | type1 | 6 |
Desc2 | type2 | 7 |
Desc2 | type3 | 8 |
I want to create a report using this dataset as below .
new Desc | count |
---|---|
Desc1 | |
type1 | 3 |
type2 | 4 |
type3 | 5 |
Desc2 | |
type1 | 6 |
type2 | 7 |
type3 | 8 |
As shown above i need to get the two variables Description and type in a sigle column with spacings. It's not a cross tabulation report so i didn't use proc tabulate. I tried with Proc Report but i am getting as different variables.
proc report data=have ;
column description type count;
define description /group "new Desc";
define type / display " ";
define count / display;
break after description/skip;
compute after description;
line " ";
endcomp;
run;
The above code is giving as separate colums instead of what i want. Can any one suggest on this.
Thanks,
Vish
Hi:
You are SO close with PROC REPORT. What you want is for DESCRIPTION to be a NOPRINT item, so you can USE it in a LINE statement in a COMPUTE BEFORE code block, but you don't see it on the report. Here's an example I had that uses SASHELP.CLASS.
cynthia
ods listing close;
ods html file='c:\temp\report.html' style=sasweb;
proc report data=sashelp.class nowd spanrows;
where age in (14, 15);
column age sex name height;
define age / order noprint;
define sex / order;
define name / display;
define height / display;
compute after age;
line ' ';
endcomp;
compute before age / style={background=yellow just=l font_weight=bold};
length myline $50;
myline = 'Age: '||put(age,2.0);
line myline $50.;
endcomp;
run;
ods html close;
Thank you Cynthia,
Its working fine and one thing is that i need to get Desc1 , below that 2 spaces then type1 and so on(as shown in the 2nd table). And i need to get like 'New Desc' for this header in report.
I am trying this in EG , the above codeis working fine but the lenght statement in compute before block is marked as red, can you suggest on this.
Regards,
Vish
Hi:
I know the LENGTH statement gets marked red in some of the editors. It's is a miscoding in the keyword/color routine. LENGTH is allowed in a COMPUTE block, but nobody told the color coding routine that LENGTH was OK. You don't get any error messages when you run the code, it's just a disconnect in the editor. Don't worry about it. It happens with PROC TEMPLATE syntax, too. Some statements just got bypassed in the color coding and they show up red, but they are OK.
If you need to get "New Desc" on the report, then you would have to put that on the DEFINE statement for TYPE, since DESCRIPTION will be a NOPRINT item, it doesn't do any good to make that label New Desc, and then blank out the header for TYPE.
So, instead of this:
DEFINE TYPE / display " ";
You would have
DEFINE TYPE / display "New Desc";
I am not sure what you mean when you say "below that 2 spaces, then type1 and so on". I assume you mean that all the values for TYPE are indented a bit underneath the values for DESC. How you will indent the values of type depends on your destination of choice. You did not say what destination you were using. Some destinations support INDENT=, some destinations support LEFTMARGIN=, some destinations do not support indenting. It just depends. You would have to implement the indent for TYPE as a STYLE override. I made a simplified example to the changed program below, so that each NAME is indented under AGE. I exaggerated the indent level so it would be very noticeable. I will leave it to you to investigate more about STYLE overrides. If INDENT= does not work with your destination of choice, whatever it is, then I would recommend that you work with Tech Support on that piece of the issue. For example, if I run just the PROC REPORT code in EG with SASReport results turned on, the INDENT= option is not used by SASReport format. I'm pretty sure that INDENT= will not work for CSV output or TEXT output either.
You can read about INDENT= here in the doc:
http://support.sas.com/documentation/cdl/en/odsug/62755/HTML/default/viewer.htm#n19a4b40swc766n18qcz... (scroll down to TEXTINDENT=, INDENT is an alias for that style attribute. I use the alias, INDENT=, because it is less typing.)
There are some very good papers about PROC REPORT floating around out on the 'Net. Here are some that I like:
http://support.sas.com/rnd/papers/sgf07/sgf2007-report.pdf
http://www.nesug.org/proceedings/nesug99/bt/bt138.PDF
http://www2.sas.com/proceedings/sugi30/244-30.pdf
http://support.sas.com/resources/papers/proceedings10/133-2010.pdf
and the original guide from the documentation is an "oldie, but goodie": http://support.sas.com/documentation/onlinedoc/v82/techreport_p258.pdf (it predates ODS, so the examples are LISTING only, but the basic "how PROC REPORT works" explanations are very thorough and useful.)
cynthia
ods listing close;
ods html file='c:\temp\report_indent.html' style=sasweb;
ods pdf file='c:\temp\report_indent.pdf';
ods rtf file='c:\temp\report_indent.rtf';
proc report data=sashelp.class nowd;
where age in (14, 15);
column age name height;
define age / order noprint;
define name / display "New Desc"
style(column)={indent=50 width=2in};
define height / display;
compute after age;
line ' ';
endcomp;
compute before age / style={background=yellow just=l font_weight=bold};
length myline $50;
myline = 'Age: '||put(age,2.0);
line myline $50.;
endcomp;
run;
ods _all_ close;
Thanks Cynthia...Its working...
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!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: