<?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: Help on PROC TRANSPOSE in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Help-on-PROC-TRANSPOSE/m-p/58521#M16446</link>
    <description>Hi Cynthia,&lt;BR /&gt;
Thanks for looking into my problem. I totally agree with the datastep solution that you have given, but i was wondering if this sort of outcome can be possible using PROC TRANSPOSE only ONCE. Just wanted confirm this up, as i believe this can't be done using PROC TRNASPOSE only once.&lt;BR /&gt;
&lt;BR /&gt;
Thanks!</description>
    <pubDate>Fri, 31 Oct 2008 03:46:43 GMT</pubDate>
    <dc:creator>SushilNayak</dc:creator>
    <dc:date>2008-10-31T03:46:43Z</dc:date>
    <item>
      <title>Help on PROC TRANSPOSE</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Help-on-PROC-TRANSPOSE/m-p/58519#M16444</link>
      <description>I've tried hard, but i think it's not possible so i thought why not ask you all before I come to any conclusion.&lt;BR /&gt;
 &lt;BR /&gt;
I have a data like this :::&lt;BR /&gt;
 &lt;BR /&gt;
Internal_id    First_nm  Last_nm  Plan_id   Country&lt;BR /&gt;
X                   Sushil     Nayak     10           IND&lt;BR /&gt;
X                   Sushil     Nayak      20          IND&lt;BR /&gt;
Z                   Dummy1  Dummy1 10          USA&lt;BR /&gt;
Z                   Dummy1  Dummy1 10          IND&lt;BR /&gt;
Y                   Dummy2 Dummy2  10         CHI&lt;BR /&gt;
Y                   Dummy2 Dummy2  20         CHI&lt;BR /&gt;
Y                   Dummy2 Dummy2  30         CHI&lt;BR /&gt;
 &lt;BR /&gt;
With this kinda of data using proc transpose only once, can we make the output like this&lt;BR /&gt;
 &lt;BR /&gt;
Internal_id    First_nm  Last_nm  Plan_id_1  Plan_id_2   Plan_id_3   Country_1  Country_2   Country_3&lt;BR /&gt;
X                  Sushil     Nayak       10               20                            IND               IND&lt;BR /&gt;
Z                  Dummy1  Dummy1   10              10                            USA              IND&lt;BR /&gt;
Y                  Dummy2 Dummy2    10              20             30            CHI               CHI            CHI &lt;BR /&gt;
 &lt;BR /&gt;
This is a sample data, my problem has plenty of other variables likes Country and Plan which force me in using PROC transpose many times. I've tried datastep manipulation as well using macro, but i wanted to know if there is any way i can convert the problematic data given above in the format like above using PROC TRANSPOSE only once.&lt;BR /&gt;
 &lt;BR /&gt;
Thanks!</description>
      <pubDate>Thu, 30 Oct 2008 12:03:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Help-on-PROC-TRANSPOSE/m-p/58519#M16444</guid>
      <dc:creator>SushilNayak</dc:creator>
      <dc:date>2008-10-30T12:03:28Z</dc:date>
    </item>
    <item>
      <title>Re: Help on PROC TRANSPOSE</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Help-on-PROC-TRANSPOSE/m-p/58520#M16445</link>
      <description>Hi:&lt;BR /&gt;
  I think that while you could do what you want with multiple transposes, you might as well use a DATA step program and ARRAYs to build your data set with numbered variables for Plan_id and Country.&lt;BR /&gt;
 &lt;BR /&gt;
  The program below creates some simple data and does what you want. There are a few assumptions about the program:&lt;BR /&gt;
1) there are no more than 5 possible rows for any unique internal_id&lt;BR /&gt;
2) first and last names are the same for every unique internal_id&lt;BR /&gt;
   &lt;BR /&gt;
cynthia&lt;BR /&gt;
[pre]&lt;BR /&gt;
** 1) Make some test data;&lt;BR /&gt;
 data plandata;&lt;BR /&gt;
  length internal_id $1 first_nm last_nm $8&lt;BR /&gt;
         Plan_id $2 Country $3;&lt;BR /&gt;
  infile datalines;&lt;BR /&gt;
  input internal_id $ first_nm $ last_nm $ Plan_id $ Country $;&lt;BR /&gt;
return;&lt;BR /&gt;
datalines;&lt;BR /&gt;
A Alan Adams 10 FRA&lt;BR /&gt;
A Alan Adams 11 BEL&lt;BR /&gt;
B Bob Baxter 11 USA&lt;BR /&gt;
B Bob Baxter 12 MEX&lt;BR /&gt;
B Bob Baxter 13 PR&lt;BR /&gt;
C Carla Castle 21 CHI&lt;BR /&gt;
C Carla Castle 22 JP&lt;BR /&gt;
C Carla Castle 23 TH&lt;BR /&gt;
C Carla Castle 24 CHI&lt;BR /&gt;
C Carla Castle 25 JP&lt;BR /&gt;
D Darla Danes 30 USA&lt;BR /&gt;
D Darla Danes 31 USA&lt;BR /&gt;
D Darla Danes 32 BEL&lt;BR /&gt;
D Darla Danes 33 FRA &lt;BR /&gt;
X Sushil Nayak 10 IND&lt;BR /&gt;
X Sushil Nayak 20 IND&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
                                 &lt;BR /&gt;
** 2) Sort the Data;&lt;BR /&gt;
proc sort data=plandata;&lt;BR /&gt;
  by internal_id first_nm last_nm Plan_id;&lt;BR /&gt;
run;&lt;BR /&gt;
                           &lt;BR /&gt;
** 3) Use a DATA Step program to create numbered variables;&lt;BR /&gt;
**    based on Internal_ID;&lt;BR /&gt;
data make_arr;&lt;BR /&gt;
  ** read in the sorted data file and turn "on" BY group;&lt;BR /&gt;
  ** processing and drop unwanted variables;&lt;BR /&gt;
  set plandata;&lt;BR /&gt;
  by internal_id;&lt;BR /&gt;
  drop country plan_id i index;&lt;BR /&gt;
                                            &lt;BR /&gt;
  ** Retain the numbered variables that we want to treat as array "members";&lt;BR /&gt;
  ** and the "index" variable that will be used in the ;&lt;BR /&gt;
  ** arrays;&lt;BR /&gt;
  retain pid1-pid5&lt;BR /&gt;
         cntry1-cntry5 index;&lt;BR /&gt;
                                            &lt;BR /&gt;
  ** Declare the ARRAYs with a max of 5 possible values;&lt;BR /&gt;
  ** for PID (Plan_ID) and CNTRY (Country);&lt;BR /&gt;
  array pid $2 pid1-pid5;&lt;BR /&gt;
  array cntry $3 cntry1-cntry5;&lt;BR /&gt;
                                  &lt;BR /&gt;
  ** Initialize the array members to spaces;&lt;BR /&gt;
  ** at the first unique internal_id -- will happen once;&lt;BR /&gt;
  ** for every unique value of internal_id;&lt;BR /&gt;
  ** (assumes that first_nm and last_nm are the same for each ID);&lt;BR /&gt;
  if first.internal_id then do;&lt;BR /&gt;
    do i = 1 to 5 by 1;&lt;BR /&gt;
       pid(i) = ' ';&lt;BR /&gt;
       cntry(i) = ' ';&lt;BR /&gt;
    end;&lt;BR /&gt;
    ** set the index variable to 0 after initializing;&lt;BR /&gt;
    index = 0;&lt;BR /&gt;
  end;&lt;BR /&gt;
                                    &lt;BR /&gt;
  ** for every row in the by group: ;&lt;BR /&gt;
  ** initialize index by 1;&lt;BR /&gt;
  ** assign the array member pid(index) the Plan_id value;&lt;BR /&gt;
  ** assign the array member cntry(index) the Country value;&lt;BR /&gt;
  index+1;  &lt;BR /&gt;
  pid(index) = plan_id;&lt;BR /&gt;
  cntry(index) = country;&lt;BR /&gt;
                              &lt;BR /&gt;
  ** because the array members are retained, when we are;&lt;BR /&gt;
  ** on the LAST of the group for internal_id, the arrays;&lt;BR /&gt;
  ** are now "filled" and we can output the new observation;&lt;BR /&gt;
  if last.internal_id then do;&lt;BR /&gt;
     arrcnt = index;&lt;BR /&gt;
     output;&lt;BR /&gt;
  end;&lt;BR /&gt;
run;&lt;BR /&gt;
                                       &lt;BR /&gt;
ods listing;&lt;BR /&gt;
options nodate nonumber nocenter;&lt;BR /&gt;
** 4) Print the new data set;&lt;BR /&gt;
ods html file='c:\temp\makearr.html' style=sasweb;&lt;BR /&gt;
proc print data=make_arr;&lt;BR /&gt;
  title 'All Plan and Country variables in numbered vars';&lt;BR /&gt;
  var internal_id first_nm last_nm arrcnt pid1-pid5 cntry1-cntry5;&lt;BR /&gt;
run;&lt;BR /&gt;
ods html close;&lt;BR /&gt;
[/pre]</description>
      <pubDate>Thu, 30 Oct 2008 22:06:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Help-on-PROC-TRANSPOSE/m-p/58520#M16445</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2008-10-30T22:06:44Z</dc:date>
    </item>
    <item>
      <title>Re: Help on PROC TRANSPOSE</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Help-on-PROC-TRANSPOSE/m-p/58521#M16446</link>
      <description>Hi Cynthia,&lt;BR /&gt;
Thanks for looking into my problem. I totally agree with the datastep solution that you have given, but i was wondering if this sort of outcome can be possible using PROC TRANSPOSE only ONCE. Just wanted confirm this up, as i believe this can't be done using PROC TRNASPOSE only once.&lt;BR /&gt;
&lt;BR /&gt;
Thanks!</description>
      <pubDate>Fri, 31 Oct 2008 03:46:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Help-on-PROC-TRANSPOSE/m-p/58521#M16446</guid>
      <dc:creator>SushilNayak</dc:creator>
      <dc:date>2008-10-31T03:46:43Z</dc:date>
    </item>
    <item>
      <title>Re: Help on PROC TRANSPOSE</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Help-on-PROC-TRANSPOSE/m-p/58522#M16447</link>
      <description>If you have less than 100 observations per "flipped group" you can use PROC SUMMARY in a one step solution.  Well 2 to get the group dimension, which would be needed for data step / array also.  Plus the variable attributes are inherited from the flipped variables.&lt;BR /&gt;
&lt;BR /&gt;
I borrowed Cynthia's data thank you.&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
data plandata;&lt;BR /&gt;
   length internal_id $1 first_nm last_nm $8&lt;BR /&gt;
           Plan_id $2 Country $3;&lt;BR /&gt;
   input internal_id $ first_nm $ last_nm $ Plan_id $ Country $;&lt;BR /&gt;
   label Plan_id = 'Plan ID' country='Country of origin';&lt;BR /&gt;
   format Plan_id $quote5.;&lt;BR /&gt;
   datalines;&lt;BR /&gt;
A Alan Adams 10 FRA&lt;BR /&gt;
A Alan Adams 11 BEL&lt;BR /&gt;
B Bob Baxter 11 USA&lt;BR /&gt;
B Bob Baxter 12 MEX&lt;BR /&gt;
B Bob Baxter 13 PR&lt;BR /&gt;
C Carla Castle 21 CHI&lt;BR /&gt;
C Carla Castle 22 JP&lt;BR /&gt;
C Carla Castle 23 TH&lt;BR /&gt;
C Carla Castle 24 CHI&lt;BR /&gt;
C Carla Castle 25 JP&lt;BR /&gt;
D Darla Danes 30 USA&lt;BR /&gt;
D Darla Danes 31 USA&lt;BR /&gt;
D Darla Danes 32 BEL&lt;BR /&gt;
D Darla Danes 33 FRA &lt;BR /&gt;
X Sushil Nayak 10 IND&lt;BR /&gt;
X Sushil Nayak 20 IND&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
&lt;B&gt;&lt;BR /&gt;
proc sql noprint;&lt;BR /&gt;
   select max(N) into :outN&lt;BR /&gt;
      from (select count(*) as N from plandata group by internal_id)&lt;BR /&gt;
      ;&lt;BR /&gt;
   quit;&lt;BR /&gt;
   run;&lt;BR /&gt;
&lt;BR /&gt;
proc summary nway missing data=plandata;&lt;BR /&gt;
   class internal_id first_nm last_nm;&lt;BR /&gt;
   output out=FlatPlan(drop=_:) idgroup(out[&amp;amp;outN](plan_id country)=);&lt;BR /&gt;
   run;&lt;BR /&gt;
&lt;/B&gt;&lt;BR /&gt;
proc contents varnum;&lt;BR /&gt;
proc print;&lt;BR /&gt;
   run;&lt;BR /&gt;
[/pre]</description>
      <pubDate>Fri, 31 Oct 2008 16:27:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Help-on-PROC-TRANSPOSE/m-p/58522#M16447</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2008-10-31T16:27:34Z</dc:date>
    </item>
    <item>
      <title>Re: Help on PROC TRANSPOSE</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Help-on-PROC-TRANSPOSE/m-p/58523#M16448</link>
      <description>Hey Null &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; ,&lt;BR /&gt;
gr8 solution. Honestly i never thought of proc summary to solve this problem....wow!!..solves my problem with just one time usage of proc sql and proc summary.&lt;BR /&gt;
&lt;BR /&gt;
Thanks!</description>
      <pubDate>Sat, 01 Nov 2008 13:15:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Help-on-PROC-TRANSPOSE/m-p/58523#M16448</guid>
      <dc:creator>SushilNayak</dc:creator>
      <dc:date>2008-11-01T13:15:01Z</dc:date>
    </item>
    <item>
      <title>Re: Help on PROC TRANSPOSE</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Help-on-PROC-TRANSPOSE/m-p/58524#M16449</link>
      <description>Hey Null/Cynthia,&lt;BR /&gt;
Just found this :: &lt;A href="http://support.sas.com/kb/33/814.html" target="_blank"&gt;http://support.sas.com/kb/33/814.html&lt;/A&gt; ... a basic solution to my problem. but not with proc transpose...but a different approach..kinda like it&lt;BR /&gt;
&lt;BR /&gt;
Thanks to SAMPLES &amp;amp; SAS NOTES for the solution :: &lt;BR /&gt;
&lt;BR /&gt;
data visits;&lt;BR /&gt;
input dovisit date9. person_id sex :$1. nvisit :$1. fvisit :$1. avisit :$1.;&lt;BR /&gt;
datalines;&lt;BR /&gt;
18dec2007 444 M T F F&lt;BR /&gt;
18dec2007 444 M T F F&lt;BR /&gt;
10jan2007 365 M T F F&lt;BR /&gt;
10jan2007 365 M T F F&lt;BR /&gt;
01feb2007 212 F T T T&lt;BR /&gt;
01feb2007 212 F T F T&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
/*create a data set of the duplicates using DUPOUT= option  */&lt;BR /&gt;
&lt;BR /&gt;
proc sort data=visits dupout=visits_dup nodupkey;&lt;BR /&gt;
  by person_id;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
/* Create a macro variable with the variable names that are to     */&lt;BR /&gt;
/* be merged.  The variables considered BY variables are excluded  */&lt;BR /&gt;
/* from going into the macro variable using the NOT IN operator.   */&lt;BR /&gt;
/* The resulting macro variable is in the format varname=varname_2 */                                              */&lt;BR /&gt;
proc sql noprint;                                                                                                                       &lt;BR /&gt;
  select trim(name) || '=' || trim(name) || '_2'                                                                                        &lt;BR /&gt;
  into :varlist separated by ' '                                                                                                        &lt;BR /&gt;
  from DICTIONARY.COLUMNS                                                                                                               &lt;BR /&gt;
  WHERE LIBNAME EQ "WORK" and MEMNAME EQ "VISITS"&lt;BR /&gt;
  and upcase(name) not in ('PERSON_ID' 'DOVISIT' 'SEX');                                                                                                                                                                                          &lt;BR /&gt;
quit;&lt;BR /&gt;
&lt;BR /&gt;
/*Merge the two data sets using the macro variable to rename the  */&lt;BR /&gt;
/*common variables in the second (duplicates) data set.           */&lt;BR /&gt;
data merged;&lt;BR /&gt;
  merge visits visits_dup (rename=(&amp;amp;varlist));&lt;BR /&gt;
  by person_id;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
proc print;&lt;BR /&gt;
run;</description>
      <pubDate>Wed, 05 Nov 2008 11:33:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Help-on-PROC-TRANSPOSE/m-p/58524#M16449</guid>
      <dc:creator>SushilNayak</dc:creator>
      <dc:date>2008-11-05T11:33:01Z</dc:date>
    </item>
  </channel>
</rss>

