<?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: How to reformat data from long to wide with dichotomizing and specific variable names in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-reformat-data-from-long-to-wide-with-dichotomizing-and/m-p/816478#M322283</link>
    <description>&lt;P&gt;It is called design matrix in statistical theory.&lt;/P&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13684"&gt;@Rick_SAS&lt;/a&gt;&amp;nbsp; wrote many blogs about it.&lt;/P&gt;
&lt;P&gt;&lt;A href="https://blogs.sas.com/content/iml/2016/02/24/create-a-design-matrix-in-sas.html" target="_blank"&gt;https://blogs.sas.com/content/iml/2016/02/24/create-a-design-matrix-in-sas.html&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://blogs.sas.com/content/iml/2017/04/19/restricted-cubic-splines-sas.html" target="_blank"&gt;https://blogs.sas.com/content/iml/2017/04/19/restricted-cubic-splines-sas.html&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data example;
input ID $  measure Item1 $ Item2 $ Item3 $;
cards;
1 -1.26 B D A 
2 -0.49 A C D 
3 1.58 B D A 
4 0.69 C D A 
5 -0.63 A C B 
;



proc glmselect data=example noprint outdesign(addinputvars)=want;
class Item: ;
model measure=Item: /selection=none noint;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sat, 04 Jun 2022 02:30:45 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2022-06-04T02:30:45Z</dc:date>
    <item>
      <title>How to reformat data from long to wide with dichotomizing and specific variable names</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-reformat-data-from-long-to-wide-with-dichotomizing-and/m-p/816405#M322239</link>
      <description>&lt;P&gt;Hello everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a dataset for an exam but need to reformat them from long to wide with specific variable names and dichotomizing all options. I can recode the answers with if then statements but it gets too long for a long test (like over 150 items). How do I achieve this through array and do loop? Thank you very much in advance!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data example;&lt;/P&gt;&lt;P&gt;input ID $&amp;nbsp; measure Item1 $ Item2 $ Item3 $;&lt;/P&gt;&lt;P&gt;cards;&lt;/P&gt;&lt;P&gt;1 -1.26 B D A&amp;nbsp;&lt;/P&gt;&lt;P&gt;2 -0.49 A C D&amp;nbsp;&lt;/P&gt;&lt;P&gt;3 1.58 B D A&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;4 0.69 C D A&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;5 -0.63 A C B&amp;nbsp;&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;input ID $ measure I1A I1B I1C I1D I2A I2B I2C I2D I3A I3B I3C I3D;&lt;/P&gt;&lt;P&gt;cards;&lt;/P&gt;&lt;P&gt;1 -1.26 0 1 0 0 0 0 0 1 1 0 0 0&lt;/P&gt;&lt;P&gt;2 -0.49 1 0 0 0 0 0 1 0 0 0 0 1&lt;/P&gt;&lt;P&gt;3 1.58 0 1 0 0 0 0 0 1 1 0 0 0&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;4 0.69 0 0 1 0 0 0 0 1 1 0 0 0&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;5 -0.63 1 0 0 0 0 0 1 0 0 1 0 0&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Variable names basically use I (for item) and 1 as the first item, then the options A, B, C, D. For answer A, it becomes 1 0 0 0, answer B is 0 1 0 0, etc. for a particular item.&lt;/P&gt;</description>
      <pubDate>Fri, 03 Jun 2022 19:40:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-reformat-data-from-long-to-wide-with-dichotomizing-and/m-p/816405#M322239</guid>
      <dc:creator>lapetitemaman</dc:creator>
      <dc:date>2022-06-03T19:40:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to reformat data from long to wide with dichotomizing and specific variable names</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-reformat-data-from-long-to-wide-with-dichotomizing-and/m-p/816425#M322247</link>
      <description>&lt;P&gt;I like PROC TRANSPOSE for this as the variables name themselves.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data example;
   input ID $  measure (Item1-Item3)($);
  cards;
1 -1.26 B D A 
2 -0.49 A C D 
3 1.58 B D A 
4 0.69 C D A 
5 -0.63 A C B 
;;;;

proc print;
   run;
proc transpose data=example out=flip;
   by id measure;
   var item:;
   run;

data flip;
   set flip(drop=id measure) flip;
   run;
proc summary data=flip nway missing completetypes classdata=flip;
    by id measure;
    class _name_ col1;
    output out=flip2;
    run;
*proc print;
   run;
proc transpose data=flip2 out=flop(drop=_name_ where=(not missing(ID))) delim=_;
   by id measure;
   id _name_ col1;
   var _freq_;
   run;
proc print;
   run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.PNG" style="width: 769px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/71992iA6A6122ECDDF6525/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.PNG" alt="Capture.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 03 Jun 2022 20:29:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-reformat-data-from-long-to-wide-with-dichotomizing-and/m-p/816425#M322247</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2022-06-03T20:29:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to reformat data from long to wide with dichotomizing and specific variable names</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-reformat-data-from-long-to-wide-with-dichotomizing-and/m-p/816439#M322251</link>
      <description>Thank you!</description>
      <pubDate>Fri, 03 Jun 2022 20:45:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-reformat-data-from-long-to-wide-with-dichotomizing-and/m-p/816439#M322251</guid>
      <dc:creator>lapetitemaman</dc:creator>
      <dc:date>2022-06-03T20:45:30Z</dc:date>
    </item>
    <item>
      <title>Re: How to reformat data from long to wide with dichotomizing and specific variable names</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-reformat-data-from-long-to-wide-with-dichotomizing-and/m-p/816478#M322283</link>
      <description>&lt;P&gt;It is called design matrix in statistical theory.&lt;/P&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13684"&gt;@Rick_SAS&lt;/a&gt;&amp;nbsp; wrote many blogs about it.&lt;/P&gt;
&lt;P&gt;&lt;A href="https://blogs.sas.com/content/iml/2016/02/24/create-a-design-matrix-in-sas.html" target="_blank"&gt;https://blogs.sas.com/content/iml/2016/02/24/create-a-design-matrix-in-sas.html&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://blogs.sas.com/content/iml/2017/04/19/restricted-cubic-splines-sas.html" target="_blank"&gt;https://blogs.sas.com/content/iml/2017/04/19/restricted-cubic-splines-sas.html&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data example;
input ID $  measure Item1 $ Item2 $ Item3 $;
cards;
1 -1.26 B D A 
2 -0.49 A C D 
3 1.58 B D A 
4 0.69 C D A 
5 -0.63 A C B 
;



proc glmselect data=example noprint outdesign(addinputvars)=want;
class Item: ;
model measure=Item: /selection=none noint;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 04 Jun 2022 02:30:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-reformat-data-from-long-to-wide-with-dichotomizing-and/m-p/816478#M322283</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2022-06-04T02:30:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to reformat data from long to wide with dichotomizing and specific variable names</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-reformat-data-from-long-to-wide-with-dichotomizing-and/m-p/816494#M322295</link>
      <description>&lt;P&gt;In addition to the links that KSharp provided, please see&lt;/P&gt;
&lt;P&gt;&lt;A href="https://blogs.sas.com/content/iml/2020/08/31/best-generate-dummy-variables-sas.html" target="_blank"&gt;The best way to generate dummy variables in SAS - The DO Loop&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 04 Jun 2022 10:16:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-reformat-data-from-long-to-wide-with-dichotomizing-and/m-p/816494#M322295</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2022-06-04T10:16:57Z</dc:date>
    </item>
  </channel>
</rss>

