<?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: Need help formatting table output is sas in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Need-help-formatting-table-output-is-sas/m-p/254207#M56946</link>
    <description>&lt;P&gt;&lt;BR /&gt;*&amp;lt;-STAT COL1 -&amp;gt; ASSIGN DEMOGRAPHICS TO &amp;gt;=1lab @facX;&lt;BR /&gt;*&amp;gt;=1lab at Facility_X;&lt;BR /&gt;%macro format;&lt;BR /&gt;format sex $newsex. newrace $race5cat. livingage&amp;amp;year. newage. risk $newrisk.;&lt;BR /&gt;%mend;&lt;BR /&gt;proc sort data=vs_Fac_pat; by cityno; run; */;&lt;BR /&gt;proc sort data=plwha; by cityno; run;&lt;BR /&gt;data Fac_demo;&lt;BR /&gt;merge vs_Fac_pat (in=a) plwha (in=b) ;&lt;BR /&gt;by cityno;&lt;BR /&gt;if a=1;&lt;BR /&gt;%format&lt;BR /&gt;*format sex $newsex. newrace $race5cat. livingage&amp;amp;year. newage. risk $newrisk.;&lt;BR /&gt;run; */Bright: 1493 Elm:1433;&lt;BR /&gt;*Run frequency for tables;&lt;BR /&gt;ods table onewayfreqs=temp;&lt;BR /&gt;proc freq data=Fac_demo order=formatted;&lt;BR /&gt;Tables sex newrace livingage&amp;amp;year. risk/missing;&lt;BR /&gt;*format sex $newsex. newrace $race5cat. livingage&amp;amp;year. newage. risk $newrisk.;&lt;BR /&gt;run; */COL1 ***;&lt;BR /&gt;*Format output;&lt;BR /&gt;data want;&lt;BR /&gt;length variable $32. variable_value $50.;&lt;BR /&gt;set temp;&lt;BR /&gt;Variable=scan(table, 2);&lt;/P&gt;&lt;P&gt;Variable_Value=strip(trim(vvaluex(variable)));&lt;/P&gt;&lt;P&gt;keep variable variable_value frequency percent:;&lt;BR /&gt;label variable='Variable'&lt;BR /&gt;variable_value='Variable Value';&lt;BR /&gt;run;&lt;BR /&gt;*Display;&lt;BR /&gt;proc print data=want label ;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;*&amp;lt;-STAT COL2-&amp;gt; ASSIGN DEMOGRAPHICS TO RETAINED (&amp;gt;=2labs 3 mo apart) ;&lt;BR /&gt;*Retained;&lt;BR /&gt;proc sort data=InCare1_pat; by cityno; run; */ citynos;&lt;BR /&gt;proc sort data=plwha; by cityno; run;&lt;BR /&gt;data InCare1_pat_demo;&lt;BR /&gt;merge InCare1_pat (in=a) plwha (in=b) ;&lt;BR /&gt;by cityno;&lt;BR /&gt;if a=1;&lt;BR /&gt;%format&lt;BR /&gt;*format sex $newsex. newrace $race5cat. livingage&amp;amp;year. newage. risk $newrisk.;&lt;BR /&gt;run; */Bright:1341 Elm: 1238;&lt;BR /&gt;*Run frequency for tables;&lt;BR /&gt;ods table onewayfreqs=temp;&lt;BR /&gt;proc freq data=InCare1_pat_demo order=formatted;&lt;BR /&gt;Tables sex newrace livingage&amp;amp;year. risk;&lt;BR /&gt;run;*/COL2 ***;&lt;BR /&gt;*Format output;&lt;BR /&gt;data want2;&lt;BR /&gt;length variable $32. variable_value $50.;&lt;BR /&gt;set temp;&lt;BR /&gt;Variable=scan(table, 2);&lt;/P&gt;&lt;P&gt;Variable_Value=strip(trim(vvaluex(variable)));&lt;/P&gt;&lt;P&gt;keep variable variable_value frequency percent:;&lt;/P&gt;&lt;P&gt;*rename variable=Variable2 ;&lt;BR /&gt;*rename variable_value=Variable_Value2;&lt;BR /&gt;rename Frequency=Frequency2;&lt;BR /&gt;run;&lt;BR /&gt;*Display;&lt;BR /&gt;proc print data=want2 label;&lt;BR /&gt;*var variable_value2 frequency;&lt;BR /&gt;run;&lt;BR /&gt;data mer;&lt;BR /&gt;set want want2;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;proc print data= mer;&lt;BR /&gt;run;&lt;/P&gt;</description>
    <pubDate>Thu, 03 Mar 2016 15:41:31 GMT</pubDate>
    <dc:creator>beverlyobeng</dc:creator>
    <dc:date>2016-03-03T15:41:31Z</dc:date>
    <item>
      <title>Need help formatting table output is sas</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Need-help-formatting-table-output-is-sas/m-p/254193#M56942</link>
      <description>&lt;P&gt;I need help formatting a table produced when ergeing to datasets. &amp;nbsp;I just need hellp shfitn the values from observation 22-39 up, The code for the merge is below and the output is attached;&lt;/P&gt;</description>
      <pubDate>Thu, 03 Mar 2016 15:25:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Need-help-formatting-table-output-is-sas/m-p/254193#M56942</guid>
      <dc:creator>beverlyobeng</dc:creator>
      <dc:date>2016-03-03T15:25:12Z</dc:date>
    </item>
    <item>
      <title>Re: Need help formatting table output is sas</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Need-help-formatting-table-output-is-sas/m-p/254197#M56943</link>
      <description>&lt;P&gt;Code?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try the code here if it's a one way frequency table, which it looks like from a quick glance.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://gist.github.com/statgeek/e0903d269d4a71316a4e" target="_blank"&gt;https://gist.github.com/statgeek/e0903d269d4a71316a4e&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 03 Mar 2016 15:27:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Need-help-formatting-table-output-is-sas/m-p/254197#M56943</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-03-03T15:27:53Z</dc:date>
    </item>
    <item>
      <title>Re: Need help formatting table output is sas</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Need-help-formatting-table-output-is-sas/m-p/254202#M56944</link>
      <description>Hi, these tables were created by a proc freq and outputted as datasets. I used the code in the link provided to achieve that. Now i would like to join the two datasets having the information in observations 22-39 shifted upwards.</description>
      <pubDate>Thu, 03 Mar 2016 15:33:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Need-help-formatting-table-output-is-sas/m-p/254202#M56944</guid>
      <dc:creator>beverlyobeng</dc:creator>
      <dc:date>2016-03-03T15:33:00Z</dc:date>
    </item>
    <item>
      <title>Re: Need help formatting table output is sas</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Need-help-formatting-table-output-is-sas/m-p/254204#M56945</link>
      <description>&lt;P&gt;I can't know that. Please include your code.&lt;/P&gt;</description>
      <pubDate>Thu, 03 Mar 2016 15:36:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Need-help-formatting-table-output-is-sas/m-p/254204#M56945</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-03-03T15:36:21Z</dc:date>
    </item>
    <item>
      <title>Re: Need help formatting table output is sas</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Need-help-formatting-table-output-is-sas/m-p/254207#M56946</link>
      <description>&lt;P&gt;&lt;BR /&gt;*&amp;lt;-STAT COL1 -&amp;gt; ASSIGN DEMOGRAPHICS TO &amp;gt;=1lab @facX;&lt;BR /&gt;*&amp;gt;=1lab at Facility_X;&lt;BR /&gt;%macro format;&lt;BR /&gt;format sex $newsex. newrace $race5cat. livingage&amp;amp;year. newage. risk $newrisk.;&lt;BR /&gt;%mend;&lt;BR /&gt;proc sort data=vs_Fac_pat; by cityno; run; */;&lt;BR /&gt;proc sort data=plwha; by cityno; run;&lt;BR /&gt;data Fac_demo;&lt;BR /&gt;merge vs_Fac_pat (in=a) plwha (in=b) ;&lt;BR /&gt;by cityno;&lt;BR /&gt;if a=1;&lt;BR /&gt;%format&lt;BR /&gt;*format sex $newsex. newrace $race5cat. livingage&amp;amp;year. newage. risk $newrisk.;&lt;BR /&gt;run; */Bright: 1493 Elm:1433;&lt;BR /&gt;*Run frequency for tables;&lt;BR /&gt;ods table onewayfreqs=temp;&lt;BR /&gt;proc freq data=Fac_demo order=formatted;&lt;BR /&gt;Tables sex newrace livingage&amp;amp;year. risk/missing;&lt;BR /&gt;*format sex $newsex. newrace $race5cat. livingage&amp;amp;year. newage. risk $newrisk.;&lt;BR /&gt;run; */COL1 ***;&lt;BR /&gt;*Format output;&lt;BR /&gt;data want;&lt;BR /&gt;length variable $32. variable_value $50.;&lt;BR /&gt;set temp;&lt;BR /&gt;Variable=scan(table, 2);&lt;/P&gt;&lt;P&gt;Variable_Value=strip(trim(vvaluex(variable)));&lt;/P&gt;&lt;P&gt;keep variable variable_value frequency percent:;&lt;BR /&gt;label variable='Variable'&lt;BR /&gt;variable_value='Variable Value';&lt;BR /&gt;run;&lt;BR /&gt;*Display;&lt;BR /&gt;proc print data=want label ;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;*&amp;lt;-STAT COL2-&amp;gt; ASSIGN DEMOGRAPHICS TO RETAINED (&amp;gt;=2labs 3 mo apart) ;&lt;BR /&gt;*Retained;&lt;BR /&gt;proc sort data=InCare1_pat; by cityno; run; */ citynos;&lt;BR /&gt;proc sort data=plwha; by cityno; run;&lt;BR /&gt;data InCare1_pat_demo;&lt;BR /&gt;merge InCare1_pat (in=a) plwha (in=b) ;&lt;BR /&gt;by cityno;&lt;BR /&gt;if a=1;&lt;BR /&gt;%format&lt;BR /&gt;*format sex $newsex. newrace $race5cat. livingage&amp;amp;year. newage. risk $newrisk.;&lt;BR /&gt;run; */Bright:1341 Elm: 1238;&lt;BR /&gt;*Run frequency for tables;&lt;BR /&gt;ods table onewayfreqs=temp;&lt;BR /&gt;proc freq data=InCare1_pat_demo order=formatted;&lt;BR /&gt;Tables sex newrace livingage&amp;amp;year. risk;&lt;BR /&gt;run;*/COL2 ***;&lt;BR /&gt;*Format output;&lt;BR /&gt;data want2;&lt;BR /&gt;length variable $32. variable_value $50.;&lt;BR /&gt;set temp;&lt;BR /&gt;Variable=scan(table, 2);&lt;/P&gt;&lt;P&gt;Variable_Value=strip(trim(vvaluex(variable)));&lt;/P&gt;&lt;P&gt;keep variable variable_value frequency percent:;&lt;/P&gt;&lt;P&gt;*rename variable=Variable2 ;&lt;BR /&gt;*rename variable_value=Variable_Value2;&lt;BR /&gt;rename Frequency=Frequency2;&lt;BR /&gt;run;&lt;BR /&gt;*Display;&lt;BR /&gt;proc print data=want2 label;&lt;BR /&gt;*var variable_value2 frequency;&lt;BR /&gt;run;&lt;BR /&gt;data mer;&lt;BR /&gt;set want want2;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;proc print data= mer;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Thu, 03 Mar 2016 15:41:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Need-help-formatting-table-output-is-sas/m-p/254207#M56946</guid>
      <dc:creator>beverlyobeng</dc:creator>
      <dc:date>2016-03-03T15:41:31Z</dc:date>
    </item>
    <item>
      <title>Re: Need help formatting table output is sas</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Need-help-formatting-table-output-is-sas/m-p/254210#M56947</link>
      <description>&lt;P&gt;Sort the data by the variables and then MERGE don't use a SET.&amp;nbsp;&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Add a row number to preserve order&lt;/LI&gt;
&lt;LI&gt;Sort by variables to merge&lt;/LI&gt;
&lt;LI&gt;Merge by variables - rename variables if required first! Variables with the same name get overwritten. The only variables that should have the same name between the datasets are the variables that you want to merge by.&lt;/LI&gt;
&lt;LI&gt;Sort by row number from 1. Look out for values that are in one table and not another, you may need to play with the sort.&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set want;
row1=_n_;
run;

data want2;
set want2;
row2=_n_;
run;

proc sort data=want;
by var1 var2;
run;

proc sort data=want2;
by var1 var2;
run;


data mer;
merge want want2;
By var1 var2;
run;

proc sort data=mer; by row1;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data mer;&lt;BR /&gt;set want want2;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;proc print data= mer;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Thu, 03 Mar 2016 15:45:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Need-help-formatting-table-output-is-sas/m-p/254210#M56947</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-03-03T15:45:05Z</dc:date>
    </item>
    <item>
      <title>Re: Need help formatting table output is sas</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Need-help-formatting-table-output-is-sas/m-p/254219#M56950</link>
      <description>&lt;P&gt;But what are var1 and var 2, are thwse the variables I have called variable and variable_value&lt;/P&gt;</description>
      <pubDate>Thu, 03 Mar 2016 15:51:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Need-help-formatting-table-output-is-sas/m-p/254219#M56950</guid>
      <dc:creator>beverlyobeng</dc:creator>
      <dc:date>2016-03-03T15:51:45Z</dc:date>
    </item>
    <item>
      <title>Re: Need help formatting table output is sas</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Need-help-formatting-table-output-is-sas/m-p/254225#M56951</link>
      <description>&lt;P&gt;Var1/Var2 are the variables that you want to line up - merge by these records.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 03 Mar 2016 15:58:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Need-help-formatting-table-output-is-sas/m-p/254225#M56951</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-03-03T15:58:03Z</dc:date>
    </item>
    <item>
      <title>Re: Need help formatting table output is sas</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Need-help-formatting-table-output-is-sas/m-p/254226#M56952</link>
      <description>&lt;P&gt;This is a good example of code which is determindly hard to read, or well obfuscated. &amp;nbsp;Consider tidying up your code so that other people can read it easily - e.g. indentations, one line per code line, consistent casing etc. &amp;nbsp;Just tidying up this part:&lt;/P&gt;
&lt;PRE&gt;%macro format;
  format sex $newsex. newrace $race5cat. livingage&amp;amp;year. newage. risk $newrisk.;
%mend;
proc sort data=vs_Fac_pat; 
  by cityno; 
run; 
proc sort data=plwha; 
  by cityno; 
run;
data Fac_demo;
  merge vs_Fac_pat (in=a) plwha (in=b) ;
  by cityno;
  if a=1;
  %format
run; 
&lt;/PRE&gt;
&lt;P&gt;Leads me to question why you have all that code when:&lt;/P&gt;
&lt;PRE&gt;proc sql;
  create table FAC_DEMO as
  select  A.*,
          B.*
  from    VS_FAC_PAT A
  left join PLWHA B
  on      A.CITYNO=B.CITYNO;
quit;

ods table onewayfreqs=temp;
proc freq data=Fac_demo;
  Tables sex newrace livingage&amp;amp;year. risk/missing;
run; &lt;/PRE&gt;
&lt;P&gt;That will give you the results - no need to do all the sorting and such like as you will need to change the layout anyways. &amp;nbsp;Can I suggest you post some test data - in the form of a datastep, and what you want the output to look like, it seems to be a straight foward demog table which has been over complicated.&lt;/P&gt;</description>
      <pubDate>Thu, 03 Mar 2016 15:58:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Need-help-formatting-table-output-is-sas/m-p/254226#M56952</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-03-03T15:58:16Z</dc:date>
    </item>
    <item>
      <title>Re: Need help formatting table output is sas</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Need-help-formatting-table-output-is-sas/m-p/254234#M56954</link>
      <description>&lt;P&gt;HI, thank you for your help thus far, but while using the merge code you provided I lost the frequencies found in the first dataset. The output is attached&lt;/P&gt;</description>
      <pubDate>Thu, 03 Mar 2016 16:09:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Need-help-formatting-table-output-is-sas/m-p/254234#M56954</guid>
      <dc:creator>beverlyobeng</dc:creator>
      <dc:date>2016-03-03T16:09:52Z</dc:date>
    </item>
    <item>
      <title>Re: Need help formatting table output is sas</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Need-help-formatting-table-output-is-sas/m-p/254246#M56955</link>
      <description>&lt;OL&gt;
&lt;LI&gt;Merge by variables - rename variables if required first! &lt;FONT color="#0000FF"&gt;&lt;STRONG&gt;Variables with the same name get overwritten. The only variables that should have the same name between the datasets are the variables that you want to merge by.&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;&lt;FONT color="#000000"&gt;Does the above apply to your merge? If so, make sure to rename the variables so they are not the same names in the two datasets before the merge.&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 03 Mar 2016 16:46:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Need-help-formatting-table-output-is-sas/m-p/254246#M56955</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-03-03T16:46:23Z</dc:date>
    </item>
    <item>
      <title>Re: Need help formatting table output is sas</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Need-help-formatting-table-output-is-sas/m-p/254284#M56962</link>
      <description>&lt;P&gt;I am still unable to produce the desired table. Sorry for all the trouble. My output is attached&lt;/P&gt;</description>
      <pubDate>Thu, 03 Mar 2016 18:43:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Need-help-formatting-table-output-is-sas/m-p/254284#M56962</guid>
      <dc:creator>beverlyobeng</dc:creator>
      <dc:date>2016-03-03T18:43:21Z</dc:date>
    </item>
  </channel>
</rss>

