<?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: SAS User Asks: Problem in transforming a database in Statistical Procedures</title>
    <link>https://communities.sas.com/t5/Statistical-Procedures/SAS-User-Asks-Problem-in-transforming-a-database/m-p/326823#M17267</link>
    <description>&lt;P&gt;OK, I'll bite.&amp;nbsp; Lets assume you have 14 variables:&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; P&amp;nbsp; (for prison)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; binary1 (0 for male, 1 for female)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; binary2 (0 for minor, 1 for adult)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; binary3&amp;nbsp;(0 for in jail, 1 for free)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var1-var10&amp;nbsp; the original variables&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Assume you want vars named like&amp;nbsp;&amp;nbsp; men_minor_jail_1 ... men_minor_jail_10, etc.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If&amp;nbsp;your data are sorted by P, then this structure would work:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want (drop=var1-var10 v);
   array x{0:1,0:1,0:1,10}
     men_minor_jail_1 - men_minor_jail_10
     men_minor_free_1 - men_minor_free_10
     men_adult_jail_1 - men_adult_jail_10
     men_adult_free_1 - men_adult_free_10

     women_minor_jail_1 - women_minor_jail_10
     women_minor_free_1 - women_minor_free_10
     women_adult_jail_1 - women_adult_jail_10
     women_adult_free_1 - women_adult_free_10;

   array vars {10} var1-var10;

   do until (last.p);
     set have;
     by p;
     do v=1 to 10;
       x{binary1,binary2,binary3,v}=vars{v};
     end;
   end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;xx&lt;/P&gt;</description>
    <pubDate>Mon, 23 Jan 2017 19:54:18 GMT</pubDate>
    <dc:creator>mkeintz</dc:creator>
    <dc:date>2017-01-23T19:54:18Z</dc:date>
    <item>
      <title>SAS User Asks: Problem in transforming a database</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/SAS-User-Asks-Problem-in-transforming-a-database/m-p/326787#M17263</link>
      <description>&lt;P&gt;&lt;SPAN&gt;From the SAS Users LinkedIn Group, SAS User &lt;A target="_blank"&gt;Daniele asks:&lt;/A&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Hi!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I would like to transform a database with 10 numeric variables, where each observation is determined by the modalities of three binary variables in a database with 80 variables (2 * 2 * 2 * 10), where each observation is no longer repeated 8 times but only 1.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I provide an example to be clear: one row contains the number of men (variable binary number 1) minor (variable binary number 2) in jail (var binary number 3) assigned to the prison p (principal variable, therefore repeated 8 times), I would in new database one row containing the data for the prison p, where the number of minor men in jail will be a specific variable of the 80 newly created.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I think I have to use arrays or a set of proc transpose, but I have some problem to imagine how I can practically do.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I hope someone can give me some suggestions!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thank you!&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Original post:&amp;nbsp;&lt;A href="https://www.linkedin.com/groups/4000846/4000846-6227792732740427779" target="_blank"&gt;https://www.linkedin.com/groups/4000846/4000846-6227792732740427779&amp;nbsp;&lt;/A&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 23 Jan 2017 17:34:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/SAS-User-Asks-Problem-in-transforming-a-database/m-p/326787#M17263</guid>
      <dc:creator>SAS_Cares</dc:creator>
      <dc:date>2017-01-23T17:34:09Z</dc:date>
    </item>
    <item>
      <title>Re: SAS User Asks: Problem in transforming a database</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/SAS-User-Asks-Problem-in-transforming-a-database/m-p/326804#M17264</link>
      <description>&lt;P&gt;It isn't helpful to post a link that requires a login / account. Not everyone has an&amp;nbsp; account on linkedin and some work locations block social media websites.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example data of input and desired output go a long way especially if provided in the form of a data step. And if the data is not SAS then this isn't the best place to ask such questions.&lt;/P&gt;</description>
      <pubDate>Mon, 23 Jan 2017 18:24:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/SAS-User-Asks-Problem-in-transforming-a-database/m-p/326804#M17264</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-01-23T18:24:01Z</dc:date>
    </item>
    <item>
      <title>Re: SAS User Asks: Problem in transforming a database</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/SAS-User-Asks-Problem-in-transforming-a-database/m-p/326810#M17266</link>
      <description>&lt;P&gt;Nothing can stimulate mental activity like a four-dimensional array.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You'll need to provide more information about the variable names (both those you have now, and those you would like to end up with).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 23 Jan 2017 18:41:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/SAS-User-Asks-Problem-in-transforming-a-database/m-p/326810#M17266</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-01-23T18:41:00Z</dc:date>
    </item>
    <item>
      <title>Re: SAS User Asks: Problem in transforming a database</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/SAS-User-Asks-Problem-in-transforming-a-database/m-p/326823#M17267</link>
      <description>&lt;P&gt;OK, I'll bite.&amp;nbsp; Lets assume you have 14 variables:&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; P&amp;nbsp; (for prison)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; binary1 (0 for male, 1 for female)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; binary2 (0 for minor, 1 for adult)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; binary3&amp;nbsp;(0 for in jail, 1 for free)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var1-var10&amp;nbsp; the original variables&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Assume you want vars named like&amp;nbsp;&amp;nbsp; men_minor_jail_1 ... men_minor_jail_10, etc.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If&amp;nbsp;your data are sorted by P, then this structure would work:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want (drop=var1-var10 v);
   array x{0:1,0:1,0:1,10}
     men_minor_jail_1 - men_minor_jail_10
     men_minor_free_1 - men_minor_free_10
     men_adult_jail_1 - men_adult_jail_10
     men_adult_free_1 - men_adult_free_10

     women_minor_jail_1 - women_minor_jail_10
     women_minor_free_1 - women_minor_free_10
     women_adult_jail_1 - women_adult_jail_10
     women_adult_free_1 - women_adult_free_10;

   array vars {10} var1-var10;

   do until (last.p);
     set have;
     by p;
     do v=1 to 10;
       x{binary1,binary2,binary3,v}=vars{v};
     end;
   end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;xx&lt;/P&gt;</description>
      <pubDate>Mon, 23 Jan 2017 19:54:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/SAS-User-Asks-Problem-in-transforming-a-database/m-p/326823#M17267</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2017-01-23T19:54:18Z</dc:date>
    </item>
    <item>
      <title>Re: SAS User Asks: Problem in transforming a database</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/SAS-User-Asks-Problem-in-transforming-a-database/m-p/326824#M17268</link>
      <description>&lt;P&gt;Had to read through a couple of times before I understood that the "binary number" is just a value to carry over and it's not a math problem; now I think it's just a simple "narrow to wide" transpose problem, probably achievable with PROC TRANSPOSE or a DATA step on sorted data with FIRST and LAST processing and/or arrays. &amp;nbsp;Here's &lt;A href="https://communities.sas.com/t5/SAS-Data-Management/Reshaping-from-long-to-wide/td-p/301946" target="_self"&gt;a thread with a similar problem/solution&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;(Note to&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;:&amp;nbsp;I think&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/124936"&gt;@SAS_Cares&lt;/a&gt;&amp;nbsp;is trying to source an answer here to help this user and others in the future. &amp;nbsp;I think we can agree there are more experts hanging out here than on the LinkedIn group.)&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, 23 Jan 2017 19:56:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/SAS-User-Asks-Problem-in-transforming-a-database/m-p/326824#M17268</guid>
      <dc:creator>ChrisHemedinger</dc:creator>
      <dc:date>2017-01-23T19:56:53Z</dc:date>
    </item>
  </channel>
</rss>

