<?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: Transposing in a Stacking Manner in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Transposing-in-a-Stacking-Manner/m-p/460552#M117072</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/74"&gt;@djbateman&lt;/a&gt; wrote:&lt;BR /&gt;Thank you. I think I can deal with converting all numeric variables to character before transposing. That will certainly clear up the second issue.&lt;BR /&gt;&lt;BR /&gt;The data will be used to see where missing values are contained. We have a spec that describes the dataset design. We want to merge the design with the actual data to see if we are missing any values that expected in the database. I hope that makes sense.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;If you add a character variable (dummy perhaps) to the VAR list in PROC TRANSPOSE SAS will do the conversion to numeric for you using any formats associated with the variables.&amp;nbsp; I call it VVALUE en masse.&lt;/P&gt;</description>
    <pubDate>Mon, 07 May 2018 18:44:31 GMT</pubDate>
    <dc:creator>data_null__</dc:creator>
    <dc:date>2018-05-07T18:44:31Z</dc:date>
    <item>
      <title>Transposing in a Stacking Manner</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transposing-in-a-Stacking-Manner/m-p/460539#M117065</link>
      <description>&lt;P&gt;I need help with transposing some datasets.&amp;nbsp; I have multiple datasets that I need transposed by some ID variables.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Below is a sample of one dataset and the transpose&amp;nbsp;procedure I am attempting to use.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data DSIS2;
      input STUDYID $12. +2 SITEID $3. +2 SUBJID $11. +2 STDYPRD 1. +2 PNINTSLP 1. +2 OPENDATE date9. +2 OPENTIME time5. +2 SAVEDATE date9. +2 SAVETIME time5.;
      format OPENDATE SAVEDATE date9. OPENTIME SAVETIME time5.;
      cards;
VX16-150-102  022  102-022-002  1  4  12DEC2017  10:19  12DEC2017  10:19
VX16-150-102  022  102-022-002  1  5  13DEC2017  10:01  13DEC2017  10:01
VX16-150-102  022  102-022-002  1  8  14DEC2017  10:01  14DEC2017  10:01
VX16-150-102  022  102-022-002  1  5  15DEC2017  10:01  15DEC2017  10:02
VX16-150-102  022  102-022-002  1  7  16DEC2017  10:00  16DEC2017  10:01
VX16-150-102  022  102-022-002  1  4  17DEC2017  10:00  17DEC2017  10:00
VX16-150-102  022  102-022-002  1  6  18DEC2017  10:01  18DEC2017  10:01
VX16-150-102  022  102-022-002  1  7  19DEC2017  05:56  19DEC2017  05:56
;
run;

proc transpose data=DSIS2 out=DSIS2_T;
      by studyid siteid subjid;
      var stdyprd pnintslp opendate opentime savedate savetime;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My goal is to get something that looks like this (spacing between groups just for demonstration--I don't actually need a blank line between groups):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;VX16-150-102  022  102-022-002  STDYPRD  1
VX16-150-102  022  102-022-002  PNINTSLP 4
VX16-150-102  022  102-022-002  OPENDATE 12DEC2017
VX16-150-102  022  102-022-002  OPENTIME 10:19
VX16-150-102  022  102-022-002  SAVEDATE 12DEC2017
VX16-150-102  022  102-022-002  SAVETIME 10:19

VX16-150-102  022  102-022-002  STDYPRD  1
VX16-150-102  022  102-022-002  PNINTSLP 5
VX16-150-102  022  102-022-002  OPENDATE 13DEC2017
VX16-150-102  022  102-022-002  OPENTIME 10:01
VX16-150-102  022  102-022-002  SAVEDATE 13DEC2017
VX16-150-102  022  102-022-002  SAVETIME 10:01

VX16-150-102  022  102-022-002  STDYPRD  1
VX16-150-102  022  102-022-002  PNINTSLP 6
VX16-150-102  022  102-022-002  OPENDATE 14DEC2017
VX16-150-102  022  102-022-002  OPENTIME 10:01
VX16-150-102  022  102-022-002  SAVEDATE 14DEC2017
VX16-150-102  022  102-022-002  SAVETIME 10:01

VX16-150-102  022  102-022-002  STDYPRD  1
VX16-150-102  022  102-022-002  PNINTSLP 5
VX16-150-102  022  102-022-002  OPENDATE 15DEC2017
VX16-150-102  022  102-022-002  OPENTIME 10:01
VX16-150-102  022  102-022-002  SAVEDATE 15DEC2017
VX16-150-102  022  102-022-002  SAVETIME 10:02

etc...&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When you open DSIS2_T, you'll see that I actually get a new column for each row (which I understand is what transposing does).&amp;nbsp; But I basically want&amp;nbsp;a stacked transposition.&amp;nbsp; Is there a shortcut way to do this rather than looping through and setting the dataset and only keeping the ID variables and the new variable of interest?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As an added caveat, notice that the date and time variables lose their formatting.&amp;nbsp; I want to keep the formatting.&amp;nbsp; Also, I have several datasets that I am trying to transpose and then stack on top of each other.&amp;nbsp; In this case, all the variables are numeric, so they come out as numeric columns, but some datasets may contain character variables, in which case I want to make all the columns character.&amp;nbsp; Is this possible in a shortened way?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My current process is:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Get a list of all the datasets I want transposed&lt;/LI&gt;&lt;LI&gt;Loop through each dataset (m times)&lt;/LI&gt;&lt;LI&gt;Get a list of all the variables I want stacked from dataset[m]&lt;/LI&gt;&lt;LI&gt;Loop through each variable (n times)&lt;/LI&gt;&lt;LI&gt;Determine the variable[n] type&lt;/LI&gt;&lt;LI&gt;Using a SET statement, stack&amp;nbsp;dataset[m] n times keeping only the ID variables and variable[n] for each set but renaming a character variable to CHAR and a numeric variable to NUM to create TABLE[m]&lt;/LI&gt;&lt;LI&gt;Make all numeric variables character using PUT()&lt;/LI&gt;&lt;LI&gt;Stack all TABLE[m] into a single table&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;There must be a simpler way than this!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 07 May 2018 18:04:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transposing-in-a-Stacking-Manner/m-p/460539#M117065</guid>
      <dc:creator>djbateman</dc:creator>
      <dc:date>2018-05-07T18:04:43Z</dc:date>
    </item>
    <item>
      <title>Re: Transposing in a Stacking Manner</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transposing-in-a-Stacking-Manner/m-p/460545#M117069</link>
      <description>&lt;P&gt;The desired result you show is not possible for all numeric values. Reason: only one format may be applied to a variable. Your appearance for your example data indicates a desire for multiple formats. At which point the process might be: determine the numeric variables, create a text version and then use a process that works for character variables.&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;PRE&gt;data DSIS2;
      input STUDYID $12. +2 SITEID $3. +2 SUBJID $11. +2 STDYPRD $1. +2 PNINTSLP $1. +2 OPENDATE $9. +2 OPENTIME $5. +2 SAVEDATE $9. +2 SAVETIME $5.;
      cards;
VX16-150-102  022  102-022-002  1  4  12DEC2017  10:19  12DEC2017  10:19
VX16-150-102  022  102-022-002  1  5  13DEC2017  10:01  13DEC2017  10:01
VX16-150-102  022  102-022-002  1  8  14DEC2017  10:01  14DEC2017  10:01
VX16-150-102  022  102-022-002  1  5  15DEC2017  10:01  15DEC2017  10:02
VX16-150-102  022  102-022-002  1  7  16DEC2017  10:00  16DEC2017  10:01
VX16-150-102  022  102-022-002  1  4  17DEC2017  10:00  17DEC2017  10:00
VX16-150-102  022  102-022-002  1  6  18DEC2017  10:01  18DEC2017  10:01
VX16-150-102  022  102-022-002  1  7  19DEC2017  05:56  19DEC2017  05:56
;
run;

data DSIS2_t;
   set DSIS2;
   array vars stdyprd pnintslp opendate opentime savedate savetime;
   length varname $ 32 value $ 10;
   do i= 1 to dim(vars);
      varname = vname(vars[i]);
      value   = vars[i];
      output;
   end;
   keep studyid siteid subjid varname value;
run;      
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please describe how the resulting data is to be used. Almost any analysis with that data structure will be extremely difficult at best.&lt;/P&gt;
&lt;P&gt;If the only reason you want that appearance is for a report then a report procedure may be of more use.&lt;/P&gt;</description>
      <pubDate>Mon, 07 May 2018 18:24:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transposing-in-a-Stacking-Manner/m-p/460545#M117069</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-05-07T18:24:41Z</dc:date>
    </item>
    <item>
      <title>Re: Transposing in a Stacking Manner</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transposing-in-a-Stacking-Manner/m-p/460547#M117070</link>
      <description>Thank you. I think I can deal with converting all numeric variables to character before transposing. That will certainly clear up the second issue.&lt;BR /&gt;&lt;BR /&gt;The data will be used to see where missing values are contained. We have a spec that describes the dataset design. We want to merge the design with the actual data to see if we are missing any values that expected in the database. I hope that makes sense.</description>
      <pubDate>Mon, 07 May 2018 18:29:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transposing-in-a-Stacking-Manner/m-p/460547#M117070</guid>
      <dc:creator>djbateman</dc:creator>
      <dc:date>2018-05-07T18:29:32Z</dc:date>
    </item>
    <item>
      <title>Re: Transposing in a Stacking Manner</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transposing-in-a-Stacking-Manner/m-p/460552#M117072</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/74"&gt;@djbateman&lt;/a&gt; wrote:&lt;BR /&gt;Thank you. I think I can deal with converting all numeric variables to character before transposing. That will certainly clear up the second issue.&lt;BR /&gt;&lt;BR /&gt;The data will be used to see where missing values are contained. We have a spec that describes the dataset design. We want to merge the design with the actual data to see if we are missing any values that expected in the database. I hope that makes sense.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;If you add a character variable (dummy perhaps) to the VAR list in PROC TRANSPOSE SAS will do the conversion to numeric for you using any formats associated with the variables.&amp;nbsp; I call it VVALUE en masse.&lt;/P&gt;</description>
      <pubDate>Mon, 07 May 2018 18:44:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transposing-in-a-Stacking-Manner/m-p/460552#M117072</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2018-05-07T18:44:31Z</dc:date>
    </item>
    <item>
      <title>Re: Transposing in a Stacking Manner</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transposing-in-a-Stacking-Manner/m-p/460559#M117075</link>
      <description>Thanks. That's an excellent idea! Now I just need to see if I can transpose in a stacking manner. It seems my best bet is to simply stack via a loop rather than trying to transpose.</description>
      <pubDate>Mon, 07 May 2018 18:58:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transposing-in-a-Stacking-Manner/m-p/460559#M117075</guid>
      <dc:creator>djbateman</dc:creator>
      <dc:date>2018-05-07T18:58:03Z</dc:date>
    </item>
    <item>
      <title>Re: Transposing in a Stacking Manner</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transposing-in-a-Stacking-Manner/m-p/460587#M117082</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/74"&gt;@djbateman&lt;/a&gt; wrote:&lt;BR /&gt;Thanks. That's an excellent idea! Now I just need to see if I can transpose in a stacking manner. It seems my best bet is to simply stack via a loop rather than trying to transpose.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Here is the code I was thinking of.&amp;nbsp; Since you need transpose by OBS but your BY variables are not unique I created a RECID to get the output you show as DSIS2_T.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data DSIS2;
      input STUDYID $12. +2 SITEID $3. +2 SUBJID $11. +2 STDYPRD 1. +2 PNINTSLP 1. +2 OPENDATE date9. +2 OPENTIME time5. +2 SAVEDATE date9. +2 SAVETIME time5.;
      format OPENDATE SAVEDATE date9. OPENTIME SAVETIME time5.;
      retain dummy '1';
      recid = _n_;
      cards;
VX16-150-102  022  102-022-002  1  4  12DEC2017  10:19  12DEC2017  10:19
VX16-150-102  022  102-022-002  1  5  13DEC2017  10:01  13DEC2017  10:01
VX16-150-102  022  102-022-002  1  8  14DEC2017  10:01  14DEC2017  10:01
VX16-150-102  022  102-022-002  1  5  15DEC2017  10:01  15DEC2017  10:02
VX16-150-102  022  102-022-002  1  7  16DEC2017  10:00  16DEC2017  10:01
VX16-150-102  022  102-022-002  1  4  17DEC2017  10:00  17DEC2017  10:00
VX16-150-102  022  102-022-002  1  6  18DEC2017  10:01  18DEC2017  10:01
VX16-150-102  022  102-022-002  1  7  19DEC2017  05:56  19DEC2017  05:56
;
run;
proc transpose data=DSIS2 out=DSIS2_T(where=(upcase(_name_) ne 'DUMMY'));
   by studyid siteid subjid recid;
   var dummy stdyprd pnintslp opendate opentime savedate savetime;
   run;
proc print;
   run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 08 May 2018 12:43:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transposing-in-a-Stacking-Manner/m-p/460587#M117082</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2018-05-08T12:43:45Z</dc:date>
    </item>
    <item>
      <title>Re: Transposing in a Stacking Manner</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transposing-in-a-Stacking-Manner/m-p/460605#M117090</link>
      <description>&lt;P&gt;Rather than transpose the dataset I would use PROC FREQ to list the values in the data and use ODS to capture that into a single table. Then you can compare it against your master list, without having to transform the original data.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/74"&gt;@djbateman&lt;/a&gt; wrote:&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;The data will be used to see where missing values are contained. We have a spec that describes the dataset design. We want to merge the design with the actual data to see if we are missing any values that expected in the database. I hope that makes sense.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 08 May 2018 00:30:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transposing-in-a-Stacking-Manner/m-p/460605#M117090</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-05-08T00:30:26Z</dc:date>
    </item>
  </channel>
</rss>

