<?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: Best way to &amp;quot;transpose&amp;quot;/make wide this data in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Best-way-to-quot-transpose-quot-make-wide-this-data/m-p/497673#M131994</link>
    <description>&lt;P&gt;For now the adding the correct var names are not too important, so I can address that later.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But using a PROC TRANSPOSE gives me something like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.JPG" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/23434i01A557AB4A6E8E14/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.JPG" alt="Capture.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It fails to re-iterate values for ID 331, instead just lumping them into the same row.&lt;/P&gt;</description>
    <pubDate>Fri, 21 Sep 2018 04:15:41 GMT</pubDate>
    <dc:creator>UniversitySas</dc:creator>
    <dc:date>2018-09-21T04:15:41Z</dc:date>
    <item>
      <title>Best way to "transpose"/make wide this data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Best-way-to-quot-transpose-quot-make-wide-this-data/m-p/497655#M131978</link>
      <description>&lt;P&gt;So, what I'm asking is not exactly a transpose (from my knowledge) and I'm finding it very tricky! Any help will be immensely appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have some sample data:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA Unclean ;
 
INFILE DATALINES ;
 input ID VAR &amp;amp; $19. CLASSIFICATION $ ;
 DATALINES;
201  PepsiCo  XYZ  
201  111 main street  XYZ  
201  Charity  XYZ  
331  CocaCola  XYZ  
331  1823 unicorn street  XYZ  
331  Charity  XYZ  
331  Nike  XYZ  
331  123 brock avenue  XYZ  
331  Charity  XYZ  
331  Adidas  XYZ  
331  14 Market street  XYZ  
331  Charity  XYZ  
354  McDonalds  XYZ  
354  111 Obesity road  XYZ  
354  Charity  XYZ  
;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;And my goal would be to get an output like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA CLEAN;
INFILE DATALINES ;
 input ID Name &amp;amp; $10. Address &amp;amp; $19. Classification $ ;
 DATALINES;
201  PepsiCo  111 main street	Charity 
331  CocaCola  1823 unicorn street  Charity   
331  Nike  123 brock avenue  Charity  
331  Adidas  14 Market street  Charity  
354  McDonalds  111 Obesity road  Charity  
;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Specifically, there are a few challenges I am having.&lt;/P&gt;&lt;P&gt;1) The IDs have uneven companies attached to them&lt;/P&gt;&lt;P&gt;2) The value "XYZ" needs to be changed to reflect things like Name, Address, and Classification.&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; Regarding 2) My fix has been that whenever we see an observation "Charity", the next observation is always a "Name".&lt;/P&gt;&lt;P&gt;Is there another way, more flexible way to approach this?&lt;/P&gt;&lt;P&gt;3) What would be the best function or command to achieve this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help is very much appreciated!&lt;/P&gt;</description>
      <pubDate>Fri, 21 Sep 2018 03:46:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Best-way-to-quot-transpose-quot-make-wide-this-data/m-p/497655#M131978</guid>
      <dc:creator>UniversitySas</dc:creator>
      <dc:date>2018-09-21T03:46:16Z</dc:date>
    </item>
    <item>
      <title>Re: Best way to "transpose"/make wide this data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Best-way-to-quot-transpose-quot-make-wide-this-data/m-p/497657#M131980</link>
      <description>Was the original format JSON or XML?&lt;BR /&gt;And didn’t that have the tags to create the classification variables?</description>
      <pubDate>Fri, 21 Sep 2018 03:49:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Best-way-to-quot-transpose-quot-make-wide-this-data/m-p/497657#M131980</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-09-21T03:49:02Z</dc:date>
    </item>
    <item>
      <title>Re: Best way to "transpose"/make wide this data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Best-way-to-quot-transpose-quot-make-wide-this-data/m-p/497658#M131981</link>
      <description>&lt;P&gt;this link should assist you with understanding how to transpose data:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://stats.idre.ucla.edu/sas/modules/how-to-reshape-data-long-to-wide-using-proc-transpose/" target="_blank"&gt;https://stats.idre.ucla.edu/sas/modules/how-to-reshape-data-long-to-wide-using-proc-transpose/&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It looks like the x = row 1, y = row 2, z = row 3&lt;/P&gt;&lt;P&gt;output your record.&lt;/P&gt;&lt;P&gt;start you count over for x,y.z;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;basically looks like 3 records per final record. &amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 21 Sep 2018 03:56:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Best-way-to-quot-transpose-quot-make-wide-this-data/m-p/497658#M131981</guid>
      <dc:creator>VDD</dc:creator>
      <dc:date>2018-09-21T03:56:58Z</dc:date>
    </item>
    <item>
      <title>Re: Best way to "transpose"/make wide this data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Best-way-to-quot-transpose-quot-make-wide-this-data/m-p/497661#M131983</link>
      <description>The data I received was a sas file actually. It's extremely granular data, and from what I've been told the original data file wouldn't have what you're asking&lt;BR /&gt;</description>
      <pubDate>Fri, 21 Sep 2018 03:52:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Best-way-to-quot-transpose-quot-make-wide-this-data/m-p/497661#M131983</guid>
      <dc:creator>UniversitySas</dc:creator>
      <dc:date>2018-09-21T03:52:18Z</dc:date>
    </item>
    <item>
      <title>Re: Best way to "transpose"/make wide this data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Best-way-to-quot-transpose-quot-make-wide-this-data/m-p/497663#M131985</link>
      <description>I've had a look at that page, I couldn't really get anything to work.&lt;BR /&gt;&lt;BR /&gt;Are you insinuating that I need to use a LOOP here?</description>
      <pubDate>Fri, 21 Sep 2018 03:59:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Best-way-to-quot-transpose-quot-make-wide-this-data/m-p/497663#M131985</guid>
      <dc:creator>UniversitySas</dc:creator>
      <dc:date>2018-09-21T03:59:02Z</dc:date>
    </item>
    <item>
      <title>Re: Best way to "transpose"/make wide this data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Best-way-to-quot-transpose-quot-make-wide-this-data/m-p/497664#M131986</link>
      <description>&lt;P&gt;yes you may need to hold record 1 and record 2 and output after obtaining record 3&lt;/P&gt;</description>
      <pubDate>Fri, 21 Sep 2018 04:01:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Best-way-to-quot-transpose-quot-make-wide-this-data/m-p/497664#M131986</guid>
      <dc:creator>VDD</dc:creator>
      <dc:date>2018-09-21T04:01:26Z</dc:date>
    </item>
    <item>
      <title>Re: Best way to "transpose"/make wide this data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Best-way-to-quot-transpose-quot-make-wide-this-data/m-p/497665#M131987</link>
      <description>If it’s always this style with three lines it’s actually trivial. If you can have varying lines per company then it’s problematic. &lt;BR /&gt;&lt;BR /&gt;Use MOD() to count lines. &lt;BR /&gt;&lt;BR /&gt;Data have;&lt;BR /&gt;Set source;&lt;BR /&gt;X=mod(_n_, 3);&lt;BR /&gt;If x=1 then class=‘name’;&lt;BR /&gt;Else if class =2 then class = ‘address’;&lt;BR /&gt;Else if class=0 then class = ‘type’;&lt;BR /&gt;&lt;BR /&gt;Retain record;&lt;BR /&gt;If x=1 record+1;&lt;BR /&gt;Run;&lt;BR /&gt;&lt;BR /&gt;Proc transpose data=have out=want;&lt;BR /&gt;By Id record;&lt;BR /&gt;Var var;&lt;BR /&gt;Id class;&lt;BR /&gt;Run;&lt;BR /&gt;&lt;BR /&gt;Untested.</description>
      <pubDate>Fri, 21 Sep 2018 04:02:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Best-way-to-quot-transpose-quot-make-wide-this-data/m-p/497665#M131987</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-09-21T04:02:27Z</dc:date>
    </item>
    <item>
      <title>Re: Best way to "transpose"/make wide this data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Best-way-to-quot-transpose-quot-make-wide-this-data/m-p/497669#M131991</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc transpose data=have out=want(drop=_name_);
   by id;
   var var;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;you will need to pass the var-names to the columns&lt;/P&gt;</description>
      <pubDate>Fri, 21 Sep 2018 04:07:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Best-way-to-quot-transpose-quot-make-wide-this-data/m-p/497669#M131991</guid>
      <dc:creator>VDD</dc:creator>
      <dc:date>2018-09-21T04:07:16Z</dc:date>
    </item>
    <item>
      <title>Re: Best way to "transpose"/make wide this data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Best-way-to-quot-transpose-quot-make-wide-this-data/m-p/497673#M131994</link>
      <description>&lt;P&gt;For now the adding the correct var names are not too important, so I can address that later.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But using a PROC TRANSPOSE gives me something like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.JPG" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/23434i01A557AB4A6E8E14/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.JPG" alt="Capture.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It fails to re-iterate values for ID 331, instead just lumping them into the same row.&lt;/P&gt;</description>
      <pubDate>Fri, 21 Sep 2018 04:15:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Best-way-to-quot-transpose-quot-make-wide-this-data/m-p/497673#M131994</guid>
      <dc:creator>UniversitySas</dc:creator>
      <dc:date>2018-09-21T04:15:41Z</dc:date>
    </item>
    <item>
      <title>Re: Best way to "transpose"/make wide this data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Best-way-to-quot-transpose-quot-make-wide-this-data/m-p/497676#M131996</link>
      <description>&lt;P&gt;you need to clean your data as&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt; has noted above first.&amp;nbsp; Then use the proc transpose.&lt;/P&gt;</description>
      <pubDate>Fri, 21 Sep 2018 04:25:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Best-way-to-quot-transpose-quot-make-wide-this-data/m-p/497676#M131996</guid>
      <dc:creator>VDD</dc:creator>
      <dc:date>2018-09-21T04:25:52Z</dc:date>
    </item>
    <item>
      <title>Re: Best way to "transpose"/make wide this data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Best-way-to-quot-transpose-quot-make-wide-this-data/m-p/497680#M131998</link>
      <description>&lt;P&gt;with cleaned up data based on&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt; datastep&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data source;
INFILE DATALINES ;
 input ID VAR &amp;amp; $19. CLASSIFICATION $ ;
 DATALINES;
201  PepsiCo  XYZ  
201  111 main street  XYZ  
201  Charity  XYZ  
331  CocaCola  XYZ  
331  1823 unicorn street  XYZ  
331  Charity  XYZ  
331  Nike  XYZ  
331  123 brock avenue  XYZ  
331  Charity  XYZ  
331  Adidas  XYZ  
331  14 Market street  XYZ  
331  Charity  XYZ  
354  McDonalds  XYZ  
354  111 Obesity road  XYZ  
354  Charity  XYZ  
;
RUN;


Data have;
length class $7;
Set source;
X=mod(_n_, 3);
If x=1 then class="name";
Else if x =2 then class = "address";
Else if x=0 then class = "type";

Retain record;
If x=1 then record+1;
Run;

Proc transpose data=have(drop=record _name_) out=want;
By Id record;
Var var;
Id class;
Run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 21 Sep 2018 04:42:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Best-way-to-quot-transpose-quot-make-wide-this-data/m-p/497680#M131998</guid>
      <dc:creator>VDD</dc:creator>
      <dc:date>2018-09-21T04:42:23Z</dc:date>
    </item>
    <item>
      <title>Re: Best way to "transpose"/make wide this data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Best-way-to-quot-transpose-quot-make-wide-this-data/m-p/497687#M132005</link>
      <description>&lt;P&gt;I suppose you don't insist on PROC TRANSPOSE. In one Data Step you will get the required output. Assumed that the Data Set is sorted by ID.&lt;/P&gt;
&lt;P&gt;The sequential records provide one of the three Variables&amp;nbsp; where LASTID can be used(except for ID = 331). For ID = 331, the alternate check with "Charity" breaks them into several records. The use of MOD(i,3) picks the relevant Value for Variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data clean;
length ID 8 Name $10 Address $19 Classification $8 Var $19; 
   do i = 1 by 1 until(last.id | Var = 'Charity');
      set unclean;
      by id notsorted;
  
      select(mod(i,3));
         when(1) Name=Var;
         when(2) Address = Var;
         when(0) Classification = Var;
         otherwise;
      end;
   end;
drop i Var;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 21 Sep 2018 05:37:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Best-way-to-quot-transpose-quot-make-wide-this-data/m-p/497687#M132005</guid>
      <dc:creator>KachiM</dc:creator>
      <dc:date>2018-09-21T05:37:08Z</dc:date>
    </item>
    <item>
      <title>Re: Best way to "transpose"/make wide this data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Best-way-to-quot-transpose-quot-make-wide-this-data/m-p/497688#M132006</link>
      <description>This is perfect, thank you so much!</description>
      <pubDate>Fri, 21 Sep 2018 05:41:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Best-way-to-quot-transpose-quot-make-wide-this-data/m-p/497688#M132006</guid>
      <dc:creator>UniversitySas</dc:creator>
      <dc:date>2018-09-21T05:41:07Z</dc:date>
    </item>
    <item>
      <title>Re: Best way to "transpose"/make wide this data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Best-way-to-quot-transpose-quot-make-wide-this-data/m-p/497689#M132007</link>
      <description>This looks fantastic - still very new to SAS so i'm very keen on working through this code you posted - it looks extremely compact!</description>
      <pubDate>Fri, 21 Sep 2018 05:41:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Best-way-to-quot-transpose-quot-make-wide-this-data/m-p/497689#M132007</guid>
      <dc:creator>UniversitySas</dc:creator>
      <dc:date>2018-09-21T05:41:35Z</dc:date>
    </item>
    <item>
      <title>Re: Best way to "transpose"/make wide this data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Best-way-to-quot-transpose-quot-make-wide-this-data/m-p/497706#M132014</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Data have;&lt;BR /&gt;length class $7;&lt;BR /&gt;Set unclean;&lt;BR /&gt;X=mod(_n_, 3);&lt;BR /&gt;If x=1 then class="name";&lt;BR /&gt;Else if x =2 then class = "address";&lt;BR /&gt;Else if x=0 then class = "type";&lt;/P&gt;&lt;P&gt;Retain record;&lt;BR /&gt;If x=1 then record+1;&lt;BR /&gt;Run;&lt;/P&gt;&lt;P&gt;Proc transpose data=have out=want(drop=CLASSIFICATION _name_ record);&lt;BR /&gt;By Id record;&lt;BR /&gt;Var var;&lt;BR /&gt;Id class;&lt;BR /&gt;Run;&lt;/P&gt;</description>
      <pubDate>Fri, 21 Sep 2018 06:56:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Best-way-to-quot-transpose-quot-make-wide-this-data/m-p/497706#M132014</guid>
      <dc:creator>srinath3111</dc:creator>
      <dc:date>2018-09-21T06:56:42Z</dc:date>
    </item>
    <item>
      <title>Re: Best way to "transpose"/make wide this data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Best-way-to-quot-transpose-quot-make-wide-this-data/m-p/497718#M132020</link>
      <description>&lt;P&gt;Hey datasp,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So one thing I just realised was that the code is not quite flexible enough; I was wondering if you had a fix.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Some of my data is organised in a way that the first 1/4 might have the recurring pattern for 9 rows, the 2nd quarter for 8 rows, the third quarter for 9 rows again and the final quarter for 7 rows.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;I understand it is a little vague since I don't have a sample of the dataset here (which I can provide if it's needed), but do you have an alternate strategy for the case above?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Would it my best bet be to break the data into separate pieces and then merge it again later, or is there another way?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 21 Sep 2018 07:42:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Best-way-to-quot-transpose-quot-make-wide-this-data/m-p/497718#M132020</guid>
      <dc:creator>UniversitySas</dc:creator>
      <dc:date>2018-09-21T07:42:24Z</dc:date>
    </item>
    <item>
      <title>Re: Best way to "transpose"/make wide this data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Best-way-to-quot-transpose-quot-make-wide-this-data/m-p/497720#M132022</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What are 9 times , 8 times and so on?&amp;nbsp; In your data set given below&lt;/P&gt;
&lt;P&gt;331 repeats 9 times. Do you mean this repetition? Just create some sample data set similar to the one you have given. Pretend to give some imaginary values to hide real values. It is then possible to check the program to give you the answer.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token procnames"&gt;data&lt;/SPAN&gt; source&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token statement"&gt;INFILE&lt;/SPAN&gt; DATALINES &lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
 &lt;SPAN class="token keyword"&gt;input&lt;/SPAN&gt; &lt;SPAN class="token keyword"&gt;ID&lt;/SPAN&gt; &lt;SPAN class="token keyword"&gt;VAR&lt;/SPAN&gt; &lt;SPAN class="token operator"&gt;&amp;amp;&lt;/SPAN&gt; &lt;SPAN class="token punctuation"&gt;$&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;19&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt; CLASSIFICATION &lt;SPAN class="token punctuation"&gt;$&lt;/SPAN&gt; &lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token datalines"&gt; &lt;SPAN class="token keyword"&gt;DATALINES&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;SPAN class="token data string"&gt;
201  PepsiCo  XYZ  
201  111 main street  XYZ  
201  Charity  XYZ  
331  CocaCola  XYZ  
331  1823 unicorn street  XYZ  
331  Charity  XYZ  
331  Nike  XYZ  
331  123 brock avenue  XYZ  
331  Charity  XYZ  
331  Adidas  XYZ  
331  14 Market street  XYZ  
331  Charity  XYZ  
354  McDonalds  XYZ  
354  111 Obesity road  XYZ  
354  Charity  XYZ  
&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/SPAN&gt;
&lt;SPAN class="token procnames"&gt;RUN&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 21 Sep 2018 07:56:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Best-way-to-quot-transpose-quot-make-wide-this-data/m-p/497720#M132022</guid>
      <dc:creator>KachiM</dc:creator>
      <dc:date>2018-09-21T07:56:20Z</dc:date>
    </item>
    <item>
      <title>Re: Best way to "transpose"/make wide this data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Best-way-to-quot-transpose-quot-make-wide-this-data/m-p/497755#M132049</link>
      <description>&lt;P&gt;You should have placed a SAMPLE Data Set that represent your real Data SET. I have given a solution based on your sample Data Set.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now you say there will be varying number of records - 2 records instead of 3. I hope you don't come with newer issues with your original Data Set.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The solution is based on first creating triplets with adding "NONE" when "Charity" is missing.&amp;nbsp; Next the same program without using LAST.ID. We can simply check for either "NONE" or "Charity" to output a record at a time.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data source;
INFILE DATALINES ;
 input ID VAR &amp;amp; $19. CLASSIFICATION $ ;
 DATALINES;
201  PepsiCo  XYZ  
201  111 main street  XYZ  
201  Charity  XYZ  
331  CocaCola  XYZ  
331  1823 unicorn street  XYZ  
331  Charity  XYZ  
331  Nike  XYZ  
331  123 brock avenue  XYZ  
331  Charity  XYZ  
331  Adidas  XYZ  
331  14 Market street  XYZ  
331  Charity  XYZ  
354  McDonalds  XYZ  
354  111 Obesity road  XYZ  
354  Charity  XYZ  
354  KFC  XYZ  
354 111 Fat Avenue  XYZ  
441  Burger King  XYZ  
441  112 Skinny ROAD  XYZ
441  Adidas  XYZ
441  Socks Blvd  XYZ
441  Tiege Henley  XYZ
441  Skincare Road  XYZ
441  Charity  XYZ
;
RUN;
proc print data = source;
run;

data have;
   set source;
   if Var = "Charity" then i = 0;
   else i+1;
   if i = 3 and Var ^= "Charity" then do; 
      temp = Var; 
      Var = "NONE";  
      output;
      Var = temp;
      output;
      temp =' ';
      i = 1;
   end;
   else output;
drop temp i;
run;

proc print data = have;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The Data Set, HAVE, will have triplets either with "NONE" or "Charity".&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The next the old program without LAST.ID checks.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data clean;
length ID 8 Name $10 Address $19 Classification $8 Var $19; 
   do i = 1 by 1 until(VAR in ("NONE","Charity"));
      set have;
      select(mod(i,3));
         when(1) Name=Var;
         when(2) Address = Var;
         when(0) Classification = Var;
         otherwise;
      end;
   end;
drop i Var;
run;
proc print data = clean;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 21 Sep 2018 10:36:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Best-way-to-quot-transpose-quot-make-wide-this-data/m-p/497755#M132049</guid>
      <dc:creator>KachiM</dc:creator>
      <dc:date>2018-09-21T10:36:41Z</dc:date>
    </item>
    <item>
      <title>Re: Best way to "transpose"/make wide this data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Best-way-to-quot-transpose-quot-make-wide-this-data/m-p/497793#M132078</link>
      <description>&lt;P&gt;that was a good one, changing source data to have addental issue not see in the sample.&lt;/P&gt;&lt;P&gt;Please post data that represents the data for testing.&lt;/P&gt;&lt;P&gt;Is the next set of data going to be missing the row 2 address line or the row 1 name line and just have the row 3?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;cleaning data is our job but have data that represents the data needing cleaning is a must.&lt;/P&gt;&lt;P&gt;this is a Q that management would ask because they would only tell me part of the story a little at a time.&amp;nbsp; Maybe that is because they just like to reconnect.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 21 Sep 2018 12:56:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Best-way-to-quot-transpose-quot-make-wide-this-data/m-p/497793#M132078</guid>
      <dc:creator>VDD</dc:creator>
      <dc:date>2018-09-21T12:56:57Z</dc:date>
    </item>
    <item>
      <title>Re: Best way to "transpose"/make wide this data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Best-way-to-quot-transpose-quot-make-wide-this-data/m-p/497812#M132089</link>
      <description>&lt;P&gt;Thanks for this - apologies about the mix-up. The data I am working with is actually huge, it wasn't until I implemented the first solution that I realised this issue persisted in the data.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;I'll give this a try; and at the same time educate myself about loops! They look a fair bit trickier in SAS than other programs I've worked with haha.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Cheers.&lt;/P&gt;</description>
      <pubDate>Fri, 21 Sep 2018 13:32:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Best-way-to-quot-transpose-quot-make-wide-this-data/m-p/497812#M132089</guid>
      <dc:creator>UniversitySas</dc:creator>
      <dc:date>2018-09-21T13:32:33Z</dc:date>
    </item>
  </channel>
</rss>

