<?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: Using transpose to divide 2 variables into multiple records each in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Using-transpose-to-divide-2-variables-into-multiple-records-each/m-p/434215#M107737</link>
    <description>&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="After transposed and merged" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/18338i58593BE4249D7402/image-size/large?v=v2&amp;amp;px=999" role="button" title="transposed and merged project.PNG" alt="After transposed and merged" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;After transposed and merged&lt;/span&gt;&lt;/span&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Data input has 7 subjects and 91 observations (only part of it is here)" style="width: 297px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/18339i4EA837EC6085D31E/image-size/large?v=v2&amp;amp;px=999" role="button" title="data input project.PNG" alt="Data input has 7 subjects and 91 observations (only part of it is here)" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;Data input has 7 subjects and 91 observations (only part of it is here)&lt;/span&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;This program is working now, I am having dropping the _label_ and _NAME_ though.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;*****IMPORT using macro code;&lt;BR /&gt;%macro P2 (a, b, c);&lt;BR /&gt;proc import out= &amp;amp;a&lt;BR /&gt;datafile= "C:\Project_2\&amp;amp;b"&lt;BR /&gt;dbms=xlsx replace;&lt;BR /&gt;getnames=yes;&lt;BR /&gt;run;&lt;BR /&gt;proc sort data=&amp;amp;a;&lt;BR /&gt;by &amp;amp;c;&lt;BR /&gt;run;&lt;BR /&gt;Proc print data = &amp;amp;a;&lt;BR /&gt;Run;&lt;BR /&gt;%mend P2;&lt;/P&gt;&lt;P&gt;%P2 (PROJECT2_F17, Project2.xlsx, subject);&lt;BR /&gt;****Restructure data using Proc transpose;&lt;/P&gt;&lt;P&gt;PROC TRANSPOSE DATA=PROJECT2_F17 OUT=P2times (DROP= _NAME_ _LABEL_) PREFIX=T;&lt;BR /&gt;BY subject;&lt;BR /&gt;VAR time ;&lt;BR /&gt;RUN;&lt;BR /&gt;PROC TRANSPOSE DATA= PROJECT2_F17 OUT=P2conc (DROP= _NAME_ _LABEL_) PREFIX=C;&lt;BR /&gt;BY subject ;&lt;BR /&gt;VAR concentration ;&lt;BR /&gt;RUN;&lt;BR /&gt;***MERGE transposed sets;&lt;BR /&gt;DATA Project2_TC;&lt;BR /&gt;merge P2times P2conc;&lt;BR /&gt;by subject;&lt;BR /&gt;run;&lt;BR /&gt;proc print data=Project2_TC;&lt;BR /&gt;run;&lt;/P&gt;</description>
    <pubDate>Mon, 05 Feb 2018 15:54:56 GMT</pubDate>
    <dc:creator>aespinarey</dc:creator>
    <dc:date>2018-02-05T15:54:56Z</dc:date>
    <item>
      <title>Using transpose to divide 2 variables into multiple records each</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-transpose-to-divide-2-variables-into-multiple-records-each/m-p/434051#M107699</link>
      <description>&lt;P&gt;Hello all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am having trouble using the &lt;STRONG&gt;&lt;FONT color="#333399"&gt;proc transpose&lt;/FONT&gt;&lt;/STRONG&gt; statement to arrange the data set to have only one observation per subject and break down 2 variables into 13 records each.&amp;nbsp;There are 7 &lt;STRONG&gt;subjects&lt;/STRONG&gt; and 13 different observations for each subject (&lt;STRONG&gt;time&lt;/STRONG&gt;s and &lt;STRONG&gt;concentrations)&lt;/STRONG&gt;. Below is my program, my variables, and the log error message.&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Variables: &lt;U&gt;Obs subject Time Concentration&amp;nbsp;&lt;/U&gt;&amp;gt;&amp;gt;&amp;gt;proc transpose&amp;gt;&amp;gt;&amp;gt;&amp;nbsp;&amp;nbsp;&lt;U&gt;Obs Subject T1 T2 T3 T4 T5 T6 T7 T8 T9 T10 T11 T12 T13 C1 C2 C3 C4 C5 C6 C7 C8 C9 C10 C11 C12 C13&lt;/U&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data results;&lt;BR /&gt;n = 0;&lt;BR /&gt;do until (last.subject);&lt;BR /&gt;set PROJECT2_F17;&lt;BR /&gt;by subject concentration;&lt;BR /&gt;if first.subject then first_time = concentration;&lt;BR /&gt;end;&lt;/P&gt;&lt;P&gt;if n = 0 then T1= time;&lt;BR /&gt;if n=0.5 then T2= time;&lt;BR /&gt;if n = 1 then T3= time;&lt;BR /&gt;if n=1.5 then T4= time;&lt;BR /&gt;if n = 2 then T5= time;&lt;BR /&gt;if n=3 then T6= time;&lt;BR /&gt;if n = 4 then T7= time;&lt;BR /&gt;if n=6 then T8= time;&lt;BR /&gt;if n = 8 then T9= time;&lt;BR /&gt;if n=12 then T10= time;&lt;BR /&gt;if n = 16 then T11= time;&lt;BR /&gt;if n=24 then T12= time;&lt;BR /&gt;else T13= time;&lt;BR /&gt;drop n time;&lt;BR /&gt;run;&lt;BR /&gt;if n = 0 then C1= concentration;&lt;BR /&gt;if n=0.5 then C2= concentration;&lt;BR /&gt;if n = 1 then C3= concentration;&lt;BR /&gt;if n=1.5 then C4= concentration;&lt;BR /&gt;if n = 2 then C5= concentration;&lt;BR /&gt;if n=3 then C6= concentration;&lt;BR /&gt;if n = 4 then C7= concentration;&lt;BR /&gt;if n=6 then C8= concentration;&lt;BR /&gt;if n = 8 then C9= concentration;&lt;BR /&gt;if n=12 then C10= concentration;&lt;BR /&gt;if n = 16 then C11= concentration;&lt;BR /&gt;if n=24 then C12= concentration;&lt;BR /&gt;else C13= concentration;&lt;BR /&gt;drop n concentration;&lt;BR /&gt;run;&lt;BR /&gt;proc print data=results;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;LOG:&lt;/P&gt;&lt;P&gt;&lt;FONT color="#993300"&gt;ERROR: BY variables are not properly sorted on data set WORK.PROJECT2_F17.&lt;/FONT&gt;&lt;BR /&gt;n=0 last.subject=0 subject=1 Time=3 Concentration=4.7 FIRST.subject=0 FIRST.Concentration=0&lt;BR /&gt;LAST.Concentration=1 first_time=0 T1=. T2=. T3=. T4=. T5=. T6=. T7=. T8=. T9=. T10=. T11=. T12=.&lt;BR /&gt;T13=. _ERROR_=1 _N_=1&lt;BR /&gt;&lt;FONT color="#0000FF"&gt;NOTE: The SAS System stopped processing this step because of errors.&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#0000FF"&gt;NOTE: There were 7 observations read from the data set WORK.PROJECT2_F17.&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#339966"&gt;WARNING: The data set WORK.RESULTS may be incomplete. When this step was stopped there were 0&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#339966"&gt;observations and 16 variables.&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#339966"&gt;WARNING: Data set WORK.RESULTS was not replaced because this step was stopped.&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#0000FF"&gt;NOTE: DATA statement used (Total process time):&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#0000FF"&gt;real time 0.02 seconds&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#0000FF"&gt;cpu time 0.01 seconds&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;108 proc print data=results;&lt;BR /&gt;109 run;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000FF"&gt;NOTE: No observations in data set WORK.RESULTS.&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#0000FF"&gt;NOTE: PROCEDURE PRINT used (Total process time):&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#0000FF"&gt;real time 0.00 seconds&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#0000FF"&gt;cpu time 0.00 seconds&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV class="branch"&gt;&lt;DIV&gt;&lt;DIV align="center"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Mon, 05 Feb 2018 06:00:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-transpose-to-divide-2-variables-into-multiple-records-each/m-p/434051#M107699</guid>
      <dc:creator>aespinarey</dc:creator>
      <dc:date>2018-02-05T06:00:47Z</dc:date>
    </item>
    <item>
      <title>Re: Using transpose to divide 2 variables into multiple records each</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-transpose-to-divide-2-variables-into-multiple-records-each/m-p/434084#M107710</link>
      <description>Please post example input data as data-step. When using BY in data-step you need to sort the data before. Later on in your code some if statements appear outside of a data-step. You need to fix this too.</description>
      <pubDate>Mon, 05 Feb 2018 08:00:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-transpose-to-divide-2-variables-into-multiple-records-each/m-p/434084#M107710</guid>
      <dc:creator>error_prone</dc:creator>
      <dc:date>2018-02-05T08:00:33Z</dc:date>
    </item>
    <item>
      <title>Re: Using transpose to divide 2 variables into multiple records each</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-transpose-to-divide-2-variables-into-multiple-records-each/m-p/434215#M107737</link>
      <description>&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="After transposed and merged" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/18338i58593BE4249D7402/image-size/large?v=v2&amp;amp;px=999" role="button" title="transposed and merged project.PNG" alt="After transposed and merged" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;After transposed and merged&lt;/span&gt;&lt;/span&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Data input has 7 subjects and 91 observations (only part of it is here)" style="width: 297px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/18339i4EA837EC6085D31E/image-size/large?v=v2&amp;amp;px=999" role="button" title="data input project.PNG" alt="Data input has 7 subjects and 91 observations (only part of it is here)" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;Data input has 7 subjects and 91 observations (only part of it is here)&lt;/span&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;This program is working now, I am having dropping the _label_ and _NAME_ though.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;*****IMPORT using macro code;&lt;BR /&gt;%macro P2 (a, b, c);&lt;BR /&gt;proc import out= &amp;amp;a&lt;BR /&gt;datafile= "C:\Project_2\&amp;amp;b"&lt;BR /&gt;dbms=xlsx replace;&lt;BR /&gt;getnames=yes;&lt;BR /&gt;run;&lt;BR /&gt;proc sort data=&amp;amp;a;&lt;BR /&gt;by &amp;amp;c;&lt;BR /&gt;run;&lt;BR /&gt;Proc print data = &amp;amp;a;&lt;BR /&gt;Run;&lt;BR /&gt;%mend P2;&lt;/P&gt;&lt;P&gt;%P2 (PROJECT2_F17, Project2.xlsx, subject);&lt;BR /&gt;****Restructure data using Proc transpose;&lt;/P&gt;&lt;P&gt;PROC TRANSPOSE DATA=PROJECT2_F17 OUT=P2times (DROP= _NAME_ _LABEL_) PREFIX=T;&lt;BR /&gt;BY subject;&lt;BR /&gt;VAR time ;&lt;BR /&gt;RUN;&lt;BR /&gt;PROC TRANSPOSE DATA= PROJECT2_F17 OUT=P2conc (DROP= _NAME_ _LABEL_) PREFIX=C;&lt;BR /&gt;BY subject ;&lt;BR /&gt;VAR concentration ;&lt;BR /&gt;RUN;&lt;BR /&gt;***MERGE transposed sets;&lt;BR /&gt;DATA Project2_TC;&lt;BR /&gt;merge P2times P2conc;&lt;BR /&gt;by subject;&lt;BR /&gt;run;&lt;BR /&gt;proc print data=Project2_TC;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Mon, 05 Feb 2018 15:54:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-transpose-to-divide-2-variables-into-multiple-records-each/m-p/434215#M107737</guid>
      <dc:creator>aespinarey</dc:creator>
      <dc:date>2018-02-05T15:54:56Z</dc:date>
    </item>
    <item>
      <title>Re: Using transpose to divide 2 variables into multiple records each</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-transpose-to-divide-2-variables-into-multiple-records-each/m-p/434223#M107739</link>
      <description>&lt;P&gt;It worked once i ran the entire program together. _LABEL_ and _NAME_ were dropped.&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="worked.PNG" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/18340i8EF055907B8677BC/image-size/large?v=v2&amp;amp;px=999" role="button" title="worked.PNG" alt="worked.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 05 Feb 2018 15:59:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-transpose-to-divide-2-variables-into-multiple-records-each/m-p/434223#M107739</guid>
      <dc:creator>aespinarey</dc:creator>
      <dc:date>2018-02-05T15:59:33Z</dc:date>
    </item>
  </channel>
</rss>

