<?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: transforming from long to wide in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/transforming-from-long-to-wide/m-p/914566#M40940</link>
    <description>&lt;P&gt;you can't, see documentation:&amp;nbsp;&lt;A href="https://documentation.sas.com/doc/ru/pgmsascdc/v_046/lepg/n1m3fal4mygiy0n1fvq8v5ax2jfn.htm" target="_blank"&gt;https://documentation.sas.com/doc/ru/pgmsascdc/v_046/lepg/n1m3fal4mygiy0n1fvq8v5ax2jfn.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
    <pubDate>Mon, 05 Feb 2024 19:43:06 GMT</pubDate>
    <dc:creator>yabwon</dc:creator>
    <dc:date>2024-02-05T19:43:06Z</dc:date>
    <item>
      <title>transforming from long to wide</title>
      <link>https://communities.sas.com/t5/New-SAS-User/transforming-from-long-to-wide/m-p/914542#M40935</link>
      <description>&lt;P&gt;Hi I am trying to transpose the population data below from long (data A) to wide (data B)&lt;/P&gt;
&lt;P&gt;Data A.&lt;/P&gt;
&lt;P&gt;age&amp;nbsp; &amp;nbsp; &amp;nbsp; pop&amp;nbsp; counties&lt;/P&gt;
&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;10&amp;nbsp; &amp;nbsp; &amp;nbsp;A&lt;/P&gt;
&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 5&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; A&lt;/P&gt;
&lt;P&gt;3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 7&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;A&lt;/P&gt;
&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;6&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;B&lt;/P&gt;
&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;B&lt;/P&gt;
&lt;P&gt;3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 5&amp;nbsp; &amp;nbsp; &amp;nbsp; B&lt;/P&gt;
&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;8&amp;nbsp; &amp;nbsp; &amp;nbsp;C&lt;/P&gt;
&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 9&amp;nbsp; &amp;nbsp; &amp;nbsp; C&lt;/P&gt;
&lt;P&gt;3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 6&amp;nbsp; &amp;nbsp; &amp;nbsp; C&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to to look like this (counties, numeric of age (1 2 3), sum total of age by county (total):&lt;/P&gt;
&lt;P&gt;Data B.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Counties&amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;3&amp;nbsp; &amp;nbsp; &amp;nbsp; total&lt;/P&gt;
&lt;P&gt;A&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;10&amp;nbsp; &amp;nbsp; &amp;nbsp; 5&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 7&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;22&lt;/P&gt;
&lt;P&gt;B&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;6&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 5&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;15&lt;/P&gt;
&lt;P&gt;C&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 8&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;9&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 6&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;23&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But the code below is not working. Thank you&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc transpose data=A out=B;
by counties;
id age;
var pop;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 05 Feb 2024 17:10:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/transforming-from-long-to-wide/m-p/914542#M40935</guid>
      <dc:creator>femiajumobi1</dc:creator>
      <dc:date>2024-02-05T17:10:59Z</dc:date>
    </item>
    <item>
      <title>Re: transforming from long to wide</title>
      <link>https://communities.sas.com/t5/New-SAS-User/transforming-from-long-to-wide/m-p/914547#M40936</link>
      <description>&lt;P&gt;The code you showed works for your example data.&amp;nbsp; So please explain what it not working.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You should add the PREFIX= option so the variable names generated are actual variable names and not digit strings.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input age pop counties $;
cards;
1 10 A
2 5 A
3 7 A
1 6 B
2 4 B
3 5 B
1 8 C
2 9 C
3 6 C
;

proc transpose data=have 
  out=want(drop=_name_) prefix=age 
;
  by counties;
  id age;
  var pop;
run;

proc print;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result&lt;/P&gt;
&lt;PRE&gt;Obs    counties    age1    age2    age3

 1        A         10       5       7
 2        B          6       4       5
 3        C          8       9       6

&lt;/PRE&gt;</description>
      <pubDate>Mon, 05 Feb 2024 18:03:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/transforming-from-long-to-wide/m-p/914547#M40936</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-02-05T18:03:31Z</dc:date>
    </item>
    <item>
      <title>Re: transforming from long to wide</title>
      <link>https://communities.sas.com/t5/New-SAS-User/transforming-from-long-to-wide/m-p/914552#M40937</link>
      <description>On adding the prefix =AGE&lt;BR /&gt;it gives beyond what is required&lt;BR /&gt;age1 age2 age3 ...........age_n&lt;BR /&gt;&lt;BR /&gt;My goal is to make the data wide with the counties as column, ages 1-3 as column and the content of the ages1-3 should be the population which I have to sum up in another column. &lt;BR /&gt;&lt;BR /&gt;First step is to get the population for each age to reflect within the ages pivoted wide. Thanks</description>
      <pubDate>Mon, 05 Feb 2024 18:28:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/transforming-from-long-to-wide/m-p/914552#M40937</guid>
      <dc:creator>femiajumobi1</dc:creator>
      <dc:date>2024-02-05T18:28:17Z</dc:date>
    </item>
    <item>
      <title>Re: transforming from long to wide</title>
      <link>https://communities.sas.com/t5/New-SAS-User/transforming-from-long-to-wide/m-p/914553#M40938</link>
      <description>&lt;P&gt;Please provide an example dataset that demonstrates the issue.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It will only give you variables (columns are something that you put into a spreadsheet or a report) for the values of AGE that exist in your dataset.&amp;nbsp; If you don't want to transpose the observations (rows are something that you put into a spreadsheet or a report) that have other values of AGE then use a WHERE statement to eliminate those observations.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to make a new variable with the total for all of the new AGEnn variables in each observation then add another step.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set want;
  total = sum(of age:);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 05 Feb 2024 18:32:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/transforming-from-long-to-wide/m-p/914553#M40938</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-02-05T18:32:55Z</dc:date>
    </item>
    <item>
      <title>Re: transforming from long to wide</title>
      <link>https://communities.sas.com/t5/New-SAS-User/transforming-from-long-to-wide/m-p/914562#M40939</link>
      <description>Thanks but How do I drop AGE from AGE1 AGE2 AGE3?&lt;BR /&gt;&lt;BR /&gt;I want to have the columns as: 1  2 3 instead of  AGE1 AGE2 AGE3</description>
      <pubDate>Mon, 05 Feb 2024 19:32:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/transforming-from-long-to-wide/m-p/914562#M40939</guid>
      <dc:creator>femiajumobi1</dc:creator>
      <dc:date>2024-02-05T19:32:15Z</dc:date>
    </item>
    <item>
      <title>Re: transforming from long to wide</title>
      <link>https://communities.sas.com/t5/New-SAS-User/transforming-from-long-to-wide/m-p/914566#M40940</link>
      <description>&lt;P&gt;you can't, see documentation:&amp;nbsp;&lt;A href="https://documentation.sas.com/doc/ru/pgmsascdc/v_046/lepg/n1m3fal4mygiy0n1fvq8v5ax2jfn.htm" target="_blank"&gt;https://documentation.sas.com/doc/ru/pgmsascdc/v_046/lepg/n1m3fal4mygiy0n1fvq8v5ax2jfn.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Mon, 05 Feb 2024 19:43:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/transforming-from-long-to-wide/m-p/914566#M40940</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2024-02-05T19:43:06Z</dc:date>
    </item>
    <item>
      <title>Re: transforming from long to wide</title>
      <link>https://communities.sas.com/t5/New-SAS-User/transforming-from-long-to-wide/m-p/914567#M40941</link>
      <description>Really? What of doing so to export as xls or csv file?</description>
      <pubDate>Mon, 05 Feb 2024 19:53:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/transforming-from-long-to-wide/m-p/914567#M40941</guid>
      <dc:creator>femiajumobi1</dc:creator>
      <dc:date>2024-02-05T19:53:47Z</dc:date>
    </item>
    <item>
      <title>Re: transforming from long to wide</title>
      <link>https://communities.sas.com/t5/New-SAS-User/transforming-from-long-to-wide/m-p/914569#M40942</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/436402"&gt;@femiajumobi1&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Thanks but How do I drop AGE from AGE1 AGE2 AGE3?&lt;BR /&gt;&lt;BR /&gt;I want to have the columns as: 1 2 3 instead of AGE1 AGE2 AGE3&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Don't use the PREFIX= option. But those are TERRIBLE names for variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want a REPORT then don't bother to make a dataset.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Just use PROC TABULATE or PROC REPORT to make your table (as in a table or figure included in your manuscript.) instead of making a dataset.&lt;/P&gt;</description>
      <pubDate>Mon, 05 Feb 2024 20:13:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/transforming-from-long-to-wide/m-p/914569#M40942</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-02-05T20:13:37Z</dc:date>
    </item>
    <item>
      <title>Re: transforming from long to wide</title>
      <link>https://communities.sas.com/t5/New-SAS-User/transforming-from-long-to-wide/m-p/914570#M40943</link>
      <description>&lt;P&gt;Exporting to text (csv) is easy, as in the DATA step you write the header line yourself:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
set your_dataset;
file "path_to_your_file" dlm="," dsd;
if _n_ = 1 then put "counties,1,2,3,total";
put
  counties
  age1
  age2
  age3
  total
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;For Excel, use ODS EXCEL, set 1,2 and 3 as labels for age1, age2 and age3, and use PROC PRINT with the LABEL option.&lt;/P&gt;</description>
      <pubDate>Mon, 05 Feb 2024 20:15:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/transforming-from-long-to-wide/m-p/914570#M40943</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2024-02-05T20:15:58Z</dc:date>
    </item>
  </channel>
</rss>

