<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: add texts to some rows in proc report in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/add-texts-to-some-rows-in-proc-report/m-p/708253#M217624</link>
    <description>&lt;P&gt;edited : 26/12/2020 -- 18:58 IST&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you mean that you want your output be like below ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE style="border-collapse: collapse; width: 144pt;" border="0" width="192" cellspacing="0" cellpadding="0"&gt;
&lt;TBODY&gt;
&lt;TR style="height: 14.5pt;"&gt;
&lt;TD width="64" height="19" class="xl65" style="height: 14.5pt; width: 48pt;"&gt;Freq&lt;/TD&gt;
&lt;TD width="64" class="xl65" style="border-left: none; width: 48pt;"&gt;Gender&lt;/TD&gt;
&lt;TD width="64" class="xl65" style="border-left: none; width: 48pt;"&gt;Color&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.5pt;"&gt;
&lt;TD width="64" height="19" class="xl66" style="height: 14.5pt; border-top: none; width: 48pt;"&gt;10&lt;/TD&gt;
&lt;TD width="64" class="xl67" style="border-top: none; border-left: none; width: 48pt;"&gt;Female&lt;/TD&gt;
&lt;TD width="64" class="xl67" style="border-top: none; border-left: none; width: 48pt;"&gt;Yellow&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.5pt;"&gt;
&lt;TD width="64" height="19" class="xl66" style="height: 14.5pt; border-top: none; width: 48pt;"&gt;15&lt;/TD&gt;
&lt;TD width="64" class="xl68" style="border-top: none; border-left: none; width: 48pt;"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="64" class="xl67" style="border-top: none; border-left: none; width: 48pt;"&gt;Red&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.5pt;"&gt;
&lt;TD width="64" height="19" class="xl66" style="height: 14.5pt; border-top: none; width: 48pt;"&gt;20&lt;/TD&gt;
&lt;TD width="64" class="xl67" style="border-top: none; border-left: none; width: 48pt;"&gt;Male&lt;/TD&gt;
&lt;TD width="64" class="xl67" style="border-top: none; border-left: none; width: 48pt;"&gt;Blue&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;if above is true then below code will work&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;Data test;
input Text $ Freq;
datalines;
F 10
M 20
Red 15
Yellow 10
Blue 20
;
run;

proc print data =test;
run;

data Gender_DATA ;
set test;
if Text='F' then Text = "Female";
else if Text='M' then Text = "Male";
if Text in ('Female','Male') then do Gender=Text ;
output ;
end;
drop Text  ;
run;

data Color_DATA;
set test;
if Text not in ('F','M') then do Color=Text ;
output;  
end;
drop Text ;
run;

/*sorting the above datasets for merge */

proc sort data=gender_data;
by Freq;
run;

proc sort data=color_data;
by Freq;
run;

data final;
merge gender_data color_data;
by freq;
run;

ods csv file="/home/u49388206/cert/excel/DATA.csv";
proc report data=Final ;
title "Sorted Data";
ods csvall close;
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 26 Dec 2020 13:29:16 GMT</pubDate>
    <dc:creator>librasonali</dc:creator>
    <dc:date>2020-12-26T13:29:16Z</dc:date>
    <item>
      <title>add texts to some rows in proc report</title>
      <link>https://communities.sas.com/t5/SAS-Programming/add-texts-to-some-rows-in-proc-report/m-p/708244#M217619</link>
      <description>&lt;P&gt;Hello everyone,&lt;/P&gt;
&lt;P&gt;I have a dataset work.test,&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
  input text $ Freq;
  datalines;
F  10
M  20
Red 15
Yellow 10
Blue 20
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;now&amp;nbsp;I&amp;nbsp;want&amp;nbsp;to&amp;nbsp;get&amp;nbsp;a&amp;nbsp;report&amp;nbsp;like&amp;nbsp;the&amp;nbsp;following:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Freq

Gender
&amp;nbsp;&amp;nbsp;Female&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;10
&amp;nbsp;&amp;nbsp;Male&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;20

Color
   Red           15
   Yellow        10
   Blue          20
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Any suggestion? Thanks.&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 26 Dec 2020 17:03:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/add-texts-to-some-rows-in-proc-report/m-p/708244#M217619</guid>
      <dc:creator>lc7033907</dc:creator>
      <dc:date>2020-12-26T17:03:11Z</dc:date>
    </item>
    <item>
      <title>Re: add texts to some rows in proc report</title>
      <link>https://communities.sas.com/t5/SAS-Programming/add-texts-to-some-rows-in-proc-report/m-p/708253#M217624</link>
      <description>&lt;P&gt;edited : 26/12/2020 -- 18:58 IST&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you mean that you want your output be like below ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE style="border-collapse: collapse; width: 144pt;" border="0" width="192" cellspacing="0" cellpadding="0"&gt;
&lt;TBODY&gt;
&lt;TR style="height: 14.5pt;"&gt;
&lt;TD width="64" height="19" class="xl65" style="height: 14.5pt; width: 48pt;"&gt;Freq&lt;/TD&gt;
&lt;TD width="64" class="xl65" style="border-left: none; width: 48pt;"&gt;Gender&lt;/TD&gt;
&lt;TD width="64" class="xl65" style="border-left: none; width: 48pt;"&gt;Color&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.5pt;"&gt;
&lt;TD width="64" height="19" class="xl66" style="height: 14.5pt; border-top: none; width: 48pt;"&gt;10&lt;/TD&gt;
&lt;TD width="64" class="xl67" style="border-top: none; border-left: none; width: 48pt;"&gt;Female&lt;/TD&gt;
&lt;TD width="64" class="xl67" style="border-top: none; border-left: none; width: 48pt;"&gt;Yellow&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.5pt;"&gt;
&lt;TD width="64" height="19" class="xl66" style="height: 14.5pt; border-top: none; width: 48pt;"&gt;15&lt;/TD&gt;
&lt;TD width="64" class="xl68" style="border-top: none; border-left: none; width: 48pt;"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="64" class="xl67" style="border-top: none; border-left: none; width: 48pt;"&gt;Red&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.5pt;"&gt;
&lt;TD width="64" height="19" class="xl66" style="height: 14.5pt; border-top: none; width: 48pt;"&gt;20&lt;/TD&gt;
&lt;TD width="64" class="xl67" style="border-top: none; border-left: none; width: 48pt;"&gt;Male&lt;/TD&gt;
&lt;TD width="64" class="xl67" style="border-top: none; border-left: none; width: 48pt;"&gt;Blue&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;if above is true then below code will work&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;Data test;
input Text $ Freq;
datalines;
F 10
M 20
Red 15
Yellow 10
Blue 20
;
run;

proc print data =test;
run;

data Gender_DATA ;
set test;
if Text='F' then Text = "Female";
else if Text='M' then Text = "Male";
if Text in ('Female','Male') then do Gender=Text ;
output ;
end;
drop Text  ;
run;

data Color_DATA;
set test;
if Text not in ('F','M') then do Color=Text ;
output;  
end;
drop Text ;
run;

/*sorting the above datasets for merge */

proc sort data=gender_data;
by Freq;
run;

proc sort data=color_data;
by Freq;
run;

data final;
merge gender_data color_data;
by freq;
run;

ods csv file="/home/u49388206/cert/excel/DATA.csv";
proc report data=Final ;
title "Sorted Data";
ods csvall close;
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 26 Dec 2020 13:29:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/add-texts-to-some-rows-in-proc-report/m-p/708253#M217624</guid>
      <dc:creator>librasonali</dc:creator>
      <dc:date>2020-12-26T13:29:16Z</dc:date>
    </item>
    <item>
      <title>Re: add texts to some rows in proc report</title>
      <link>https://communities.sas.com/t5/SAS-Programming/add-texts-to-some-rows-in-proc-report/m-p/708257#M217639</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
  input text $ Freq;
  datalines;
F  10
M  20
Red 15
Yellow 10
Blue 20
;
run;

proc sql;
create table have1 as
select Freq,
       case when text eq 'F' then 'Female' 
            when text eq 'M' then 'Male' end as Gender
	        from test where calculated Gender ne '';
create table have2 as
select Freq,
       case when text not in ('F','M') then text end as color 
       from test where calculated color ne '';
create table want as
select COALESCE(a.freq,b.freq) as Freq,Gender,b.color from have1 as a full join have2 as b on a.freq =b.freq;
quit;



           &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Want dataset is your final data. you can use any export technique to take in desired output format.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 26 Dec 2020 09:43:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/add-texts-to-some-rows-in-proc-report/m-p/708257#M217639</guid>
      <dc:creator>singhsahab</dc:creator>
      <dc:date>2020-12-26T09:43:43Z</dc:date>
    </item>
    <item>
      <title>Re: add texts to some rows in proc report</title>
      <link>https://communities.sas.com/t5/SAS-Programming/add-texts-to-some-rows-in-proc-report/m-p/708275#M217649</link>
      <description>Hello, thank you for your reply. I tried your method, but it's not what I&lt;BR /&gt;want. With your code, there is one column, Gender, no value in it. I want&lt;BR /&gt;to add categorization words before text. For example, one row called&lt;BR /&gt;"Gener", then Female and male are underneath it with some indent. Then&lt;BR /&gt;"Color" and the rest three underneath it.&lt;BR /&gt;</description>
      <pubDate>Sat, 26 Dec 2020 16:03:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/add-texts-to-some-rows-in-proc-report/m-p/708275#M217649</guid>
      <dc:creator>lc7033907</dc:creator>
      <dc:date>2020-12-26T16:03:53Z</dc:date>
    </item>
    <item>
      <title>Re: add texts to some rows in proc report</title>
      <link>https://communities.sas.com/t5/SAS-Programming/add-texts-to-some-rows-in-proc-report/m-p/708278#M217651</link>
      <description>Can you post a screen shot of your desire output?</description>
      <pubDate>Sat, 26 Dec 2020 16:08:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/add-texts-to-some-rows-in-proc-report/m-p/708278#M217651</guid>
      <dc:creator>singhsahab</dc:creator>
      <dc:date>2020-12-26T16:08:28Z</dc:date>
    </item>
    <item>
      <title>Re: add texts to some rows in proc report</title>
      <link>https://communities.sas.com/t5/SAS-Programming/add-texts-to-some-rows-in-proc-report/m-p/708285#M217654</link>
      <description>&lt;PRE&gt;/*UPDATED CODE*/&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Data test;
input Text $ Freq;
datalines;
F 10
M 20
Red 15
Yellow 10
Blue 20
;
run;

proc print data =test;
run;

data Gender_DATA ;
set test;
if Text='F' then Text = "Female";
else if Text='M' then Text = "Male";
if Text in ('Female','Male') then do Gender=Text ;
output ;
end;
drop Text  ;
run;

data Color_DATA;
set test;
if Text not in ('F','M') then do Color=Text ;
output;  
end;
drop Text ;
run;

/*sorting the above datasets for merge */

proc sort data=gender_data;
by Freq;
run;

proc sort data=color_data;
by Freq;
run;

data final;
merge gender_data color_data;
by freq;
run;

/* This is will create report*/
PROC TABULATE data=Final;
CLASS  Gender Color / MISSING;
var freq;
TABLE freq , Gender, Color;
RUN;&lt;/PRE&gt;
&lt;P&gt;&lt;STRONG&gt;OUTPUT :&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="librasonali_0-1609001893870.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/53033iA1B8A3F8FE0C7091/image-size/medium?v=v2&amp;amp;px=400" role="button" title="librasonali_0-1609001893870.png" alt="librasonali_0-1609001893870.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;from your reply I can figure out that above is the expected output you desire.. ??&lt;/P&gt;</description>
      <pubDate>Sat, 26 Dec 2020 16:59:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/add-texts-to-some-rows-in-proc-report/m-p/708285#M217654</guid>
      <dc:creator>librasonali</dc:creator>
      <dc:date>2020-12-26T16:59:57Z</dc:date>
    </item>
    <item>
      <title>Re: add texts to some rows in proc report</title>
      <link>https://communities.sas.com/t5/SAS-Programming/add-texts-to-some-rows-in-proc-report/m-p/708286#M217655</link>
      <description>THANKS FOR THE PROC SQL VERSION  Answer for this question !</description>
      <pubDate>Sat, 26 Dec 2020 17:01:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/add-texts-to-some-rows-in-proc-report/m-p/708286#M217655</guid>
      <dc:creator>librasonali</dc:creator>
      <dc:date>2020-12-26T17:01:45Z</dc:date>
    </item>
    <item>
      <title>Re: add texts to some rows in proc report</title>
      <link>https://communities.sas.com/t5/SAS-Programming/add-texts-to-some-rows-in-proc-report/m-p/708287#M217656</link>
      <description>&lt;P&gt;The first thing you need to do is convert that data into something that more actually reflects the data.&amp;nbsp; Currently there is no way to know which variable each row represents.&amp;nbsp; For example you could add a column that shows the variable name.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data real_data ;
  length varname $32 ;
  set test;
  if _n_ in (1:2) then varname='Gender';
  else varname='Color';
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;results&lt;/P&gt;
&lt;PRE&gt;Obs    varname    text      Freq

 1     Gender     F          10
 2     Gender     M          20
 3     Color      Red        15
 4     Color      Yellow     10
 5     Color      Blue       20&lt;/PRE&gt;
&lt;P&gt;Now you can use VARNAME as an group/order variable in PROC REPORT.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc report data=real_data ;
  columns varname text freq ;
  define varname / order order=data noprint;
  define text / order order=data ' ';
  compute before varname ;
     line @1 varname $32. ;
  endcomp;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Results&lt;/P&gt;
&lt;PRE&gt;                 Freq
Gender
  F                10
  M                20
Color
  Red              15
  Yellow           10
  Blue             20&lt;/PRE&gt;</description>
      <pubDate>Sat, 26 Dec 2020 17:23:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/add-texts-to-some-rows-in-proc-report/m-p/708287#M217656</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-12-26T17:23:42Z</dc:date>
    </item>
  </channel>
</rss>

