<?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 SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Transposing/m-p/788256#M251982</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID $ Vit_D CRP date :mmddyy10.;
format date mmddyy10.;
cards;
00-01 12 5.5 09/05/2021
00-01 15 1.6 10/12/2021
00-03 18 3.9 10/17/2021
00-03 26 3.8 09/16/2021
00-05 36 1.5 09/01/2021
00-05 30 0.8 10/20/2021
00-06 43 10.3 09/24/2021
00-06 52 0.8 10/25/2021
;

data temp;
set have;
by id;
if first.id then n=0;
n+1;
run;
proc sql noprint;
select distinct catt('temp(where=(n=',n,') rename=(Vit_D=Vit_D_',n,' CRP=CRP_',n,' date=date_',n,'))')
 into : merge separated by ' '
  from temp;
quit;
data want;
 merge &amp;amp;merge;
 by id;
 drop n;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 04 Jan 2022 11:56:01 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2022-01-04T11:56:01Z</dc:date>
    <item>
      <title>Transposing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transposing/m-p/788225#M251959</link>
      <description>&lt;P&gt;Wish everyone a Happy and Prosperous New Year!!!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I and trying to transpose the following data based on date.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data have;&lt;BR /&gt;input ID $ Vit_D CRP date :mmddyy10.;&lt;BR /&gt;format date mmddyy10.;&lt;BR /&gt;cards;&lt;BR /&gt;00-01 12 5.5 09/05/2021&lt;BR /&gt;00-01 15 1.6 10/12/2021&lt;BR /&gt;00-03 18 3.9 10/17/2021&lt;BR /&gt;00-03 26 3.8 09/16/2021&lt;BR /&gt;00-05 36 1.5 09/01/2021&lt;BR /&gt;00-05 30 0.8 10/20/2021&lt;BR /&gt;00-06 43 10.3 09/24/2021&lt;BR /&gt;00-06 52 0.8 10/25/2021&lt;BR /&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The outcome I am trying to get is following.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data have_1;&lt;BR /&gt;input ID $ Vit_D_1 CRP_1 date_1 :mmddyy10. Vit_D_2 CRP_2 date_2 :mmddyy10.;&lt;BR /&gt;format date_1 mmddyy10. date_2 mmddyy10.;&lt;BR /&gt;cards;&lt;BR /&gt;00-01 12 5.5 09/05/2021 15 1.6 10/12/2021&lt;BR /&gt;00-03 18 3.9 10/17/2021 26 3.8 09/16/2021&lt;BR /&gt;00-05 36 1.5 09/01/2021 30 0.8 10/20/2021&lt;BR /&gt;00-06 43 10.3 09/24/2021 52 0.8 10/25/2021&lt;BR /&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am struggling because I am trying to do it based on dates. Could anyone help.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks you very much!&lt;/P&gt;&lt;P&gt;Rube&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 04 Jan 2022 04:57:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transposing/m-p/788225#M251959</guid>
      <dc:creator>sandrube</dc:creator>
      <dc:date>2022-01-04T04:57:15Z</dc:date>
    </item>
    <item>
      <title>Re: Transposing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transposing/m-p/788233#M251962</link>
      <description>&lt;P&gt;The structure of HAVE is almost always the preferred one, because it is easier to use in most procedures: you have to write less code. So the question arises: why do you need a wide dataset?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you insist on transposing: You have to call proc transpose for each variable you want transposed.&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc transpose data=have out=t_date(drop=_name_) prefix=date_;
   by id;
   var date;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And finally you have to merge all the created datasets.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If your dataset is large, the following step might perform better:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
%macro transpose;
   %local maxCount;
   
   proc sql noprint;
      select max(count) into :maxCount trimmed
         from (
         select count(Id) as count
            from work.have 
               group by id
         );
   quit;


   data want;
      set have;
      by Id;
      
      length
         %do i = 1 %to &amp;amp;maxCount.;
            vit_d_&amp;amp;i. crp_&amp;amp;i. date_&amp;amp;i. 8
         %end;
      ;
      
      format date_: mmddyy10.;
      
      retain i vit_d_: crp_: date_:;
      
      array vits[&amp;amp;maxCount.] vit_d_1 - vit_d_&amp;amp;maxCount.;
      array crps[&amp;amp;maxCount.] crp_1 - crp_&amp;amp;maxCount.;
      array dates[&amp;amp;maxCount.] date_1 - date_&amp;amp;maxCount.;      
      
      if first.Id then do;
         call missing(of vit_d_:, of crp_:, of date_:);
         i = 1;
      end;
      
      vits[i] = vit_d;
      crps[i] = crp;
      dates[i] = date;
      
      i = i + 1;
      
      if last.Id then do;
         output;
      end;
      
      drop i crp vit_d date;
   run;
%mend;


%transpose;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 04 Jan 2022 07:08:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transposing/m-p/788233#M251962</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2022-01-04T07:08:21Z</dc:date>
    </item>
    <item>
      <title>Re: Transposing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transposing/m-p/788256#M251982</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID $ Vit_D CRP date :mmddyy10.;
format date mmddyy10.;
cards;
00-01 12 5.5 09/05/2021
00-01 15 1.6 10/12/2021
00-03 18 3.9 10/17/2021
00-03 26 3.8 09/16/2021
00-05 36 1.5 09/01/2021
00-05 30 0.8 10/20/2021
00-06 43 10.3 09/24/2021
00-06 52 0.8 10/25/2021
;

data temp;
set have;
by id;
if first.id then n=0;
n+1;
run;
proc sql noprint;
select distinct catt('temp(where=(n=',n,') rename=(Vit_D=Vit_D_',n,' CRP=CRP_',n,' date=date_',n,'))')
 into : merge separated by ' '
  from temp;
quit;
data want;
 merge &amp;amp;merge;
 by id;
 drop n;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 04 Jan 2022 11:56:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transposing/m-p/788256#M251982</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2022-01-04T11:56:01Z</dc:date>
    </item>
    <item>
      <title>Re: Transposing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transposing/m-p/788412#M252079</link>
      <description>very elegant program  !&lt;BR /&gt;</description>
      <pubDate>Wed, 05 Jan 2022 09:23:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transposing/m-p/788412#M252079</guid>
      <dc:creator>AndreaVianello</dc:creator>
      <dc:date>2022-01-05T09:23:40Z</dc:date>
    </item>
  </channel>
</rss>

