<?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: Need help transposing longitudinal data (HRS) and creation of time variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Need-help-transposing-longitudinal-data-HRS-and-creation-of-time/m-p/913571#M360065</link>
    <description>&lt;P&gt;I've got some theory what could be happening but to really know and propose code that works you need to provide us with sample data and code that ideally allows us to replicate what you describe.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To create sample data you could use code similar to below. Please make sure that the sample data is representative for the by groups like is the combination of hhidpn and ssri the business key or not?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And ideally the sample data and code you provide lets us replicate the issue you describe.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data ucognition;
  HHIDPN='A'; 
  SSRI='X';
  array cog{6} 8 (1,2,3,4,5,6);
  output;
  SSRI='Y';
  output;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Also please post code that actually works in your environment. This bit you shared will create a syntax error.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_0-1706615599744.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/93065iE584E65A9E8EC624/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Patrick_0-1706615599744.png" alt="Patrick_0-1706615599744.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;And also try to provide consistent info. Like: Where does this unnamed column with ID&amp;lt;n&amp;gt; values suddenly come from?&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_1-1706615666642.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/93066i866DC4C7F35B802E/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Patrick_1-1706615666642.png" alt="Patrick_1-1706615666642.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 30 Jan 2024 11:56:59 GMT</pubDate>
    <dc:creator>Patrick</dc:creator>
    <dc:date>2024-01-30T11:56:59Z</dc:date>
    <item>
      <title>Need help transposing longitudinal data (HRS) and creation of time variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-help-transposing-longitudinal-data-HRS-and-creation-of-time/m-p/913490#M360054</link>
      <description>&lt;P&gt;I have data with ID, repeated cognitive measure (cog1-cog6), and medication (SSRI) at start. I will eventually run the mixed procedure to determine the association between cognitive score at the time points and SSRI.&lt;/P&gt;&lt;P&gt;My code looks like:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;**getting relevant variables;

data ucognition;
set analyze (keep=
HHIDPN SSRI 
cog1 cog2 cog3 cog4 cog5 cog6); 
run;


proc transpose data=ucognition out=longcog (rename =(col1=CogScore) rename = (_name_=cog));
by HHIDPN SSRI;
var cog1 cog2 cog3 cog4 cog5 cog6;
run;

proc print data=longcog (obs=10);
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;the transpose works as it should, and cog1-cog6 are stored in long format under cog&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;when i go to create a time variable, this is my code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;data longcog2;
set longcog;
cog=cog1; time=1; output;
cog=cog2; time=2; output;
cog=cog3; time=3; output;
cog=cog4; time=4; output;
cog=cog5; time=5; output;
cog=cog6; time=6; output;
keep HHIDPN SSRI time cog;
run;

proc print data=longcog2 (obs=10);
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;However, now, SAS states that cog1-6 are all uninitialized, so the time doesn't get assigned to them.&lt;/P&gt;&lt;P&gt;Is there a reason it isnt being recognized? Everything is in numeric format. I am unsure if I should rename the cog variable? The initial data has it has r7cogtot = cog1, r8cogtot = cog2, etc.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like my final table to look like:&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;SSRI&amp;nbsp; &amp;nbsp; &amp;nbsp;cog&amp;nbsp; &amp;nbsp; cogscore&lt;/P&gt;&lt;P&gt;id1&amp;nbsp; &amp;nbsp; &amp;nbsp; yes&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;cog1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;14&lt;/P&gt;&lt;P&gt;id1&amp;nbsp; &amp;nbsp; &amp;nbsp; yes&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;cog2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;13&lt;/P&gt;&lt;P&gt;id1&amp;nbsp; &amp;nbsp; &amp;nbsp; yes&amp;nbsp; &amp;nbsp; &amp;nbsp; ...&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;13&lt;/P&gt;&lt;P&gt;id1&amp;nbsp; &amp;nbsp; &amp;nbsp; yes&amp;nbsp; &amp;nbsp; &amp;nbsp; ...&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 13&lt;/P&gt;&lt;P&gt;id1&amp;nbsp; &amp;nbsp; &amp;nbsp; yes&amp;nbsp; &amp;nbsp; &amp;nbsp; ...&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ...&lt;/P&gt;&lt;P&gt;id1&amp;nbsp; &amp;nbsp; &amp;nbsp; yes&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;cog6&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;...&lt;/P&gt;&lt;P&gt;id2&amp;nbsp; &amp;nbsp; &amp;nbsp;yes&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;cog1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 25&lt;/P&gt;&lt;P&gt;id2&amp;nbsp; &amp;nbsp; &amp;nbsp;yes&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;...&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;25&lt;/P&gt;&lt;P&gt;...&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ...&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;....&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ....&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if i code the transpose like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;data ucognition;
set analyze (keep=
HHIDPN SSRI 
cog1 cog2 cog3 cog4 cog5 cog6); 
run;


proc transpose data=ucognition out=longcog (rename =(col1=CogScore) rename = (_name_=cog));
by HHIDPN SSRI **cog1 cog2 cog3 cog4 cog5 cog6**;
var cog1 cog2 cog3 cog4 cog5 cog6
    ;
run;

proc print data=longcog (obs=10);
run;

data longcog2;
set longcog;
cog=cog1; time=1; output;
cog=cog2; time=2; output;
cog=cog3; time=3; output;
cog=cog4; time=4; output;
cog=cog5; time=5; output;
cog=cog6; time=6; output;
keep HHIDPN SSRI time cog;
run;

proc print data=longcog2 (obs=10);
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;I get the right output and time works, but it repeats each person 6 times&lt;/P&gt;&lt;P&gt;like&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;id1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;SSRI&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;cog&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;cogscore&lt;/P&gt;&lt;P&gt;id1&lt;/P&gt;&lt;P&gt;id1&lt;/P&gt;&lt;P&gt;... 36 times&lt;/P&gt;&lt;P&gt;id2&lt;/P&gt;&lt;P&gt;id2&lt;/P&gt;&lt;P&gt;...36 times&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any idea why this is happening?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 30 Jan 2024 01:22:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-help-transposing-longitudinal-data-HRS-and-creation-of-time/m-p/913490#M360054</guid>
      <dc:creator>sas_user124</dc:creator>
      <dc:date>2024-01-30T01:22:21Z</dc:date>
    </item>
    <item>
      <title>Re: Need help transposing longitudinal data (HRS) and creation of time variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-help-transposing-longitudinal-data-HRS-and-creation-of-time/m-p/913571#M360065</link>
      <description>&lt;P&gt;I've got some theory what could be happening but to really know and propose code that works you need to provide us with sample data and code that ideally allows us to replicate what you describe.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To create sample data you could use code similar to below. Please make sure that the sample data is representative for the by groups like is the combination of hhidpn and ssri the business key or not?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And ideally the sample data and code you provide lets us replicate the issue you describe.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data ucognition;
  HHIDPN='A'; 
  SSRI='X';
  array cog{6} 8 (1,2,3,4,5,6);
  output;
  SSRI='Y';
  output;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Also please post code that actually works in your environment. This bit you shared will create a syntax error.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_0-1706615599744.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/93065iE584E65A9E8EC624/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Patrick_0-1706615599744.png" alt="Patrick_0-1706615599744.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;And also try to provide consistent info. Like: Where does this unnamed column with ID&amp;lt;n&amp;gt; values suddenly come from?&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_1-1706615666642.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/93066i866DC4C7F35B802E/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Patrick_1-1706615666642.png" alt="Patrick_1-1706615666642.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 30 Jan 2024 11:56:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-help-transposing-longitudinal-data-HRS-and-creation-of-time/m-p/913571#M360065</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2024-01-30T11:56:59Z</dc:date>
    </item>
    <item>
      <title>Re: Need help transposing longitudinal data (HRS) and creation of time variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-help-transposing-longitudinal-data-HRS-and-creation-of-time/m-p/913578#M360068</link>
      <description>&lt;P&gt;When you do this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;proc transpose data=ucognition out=longcog (rename =(col1=CogScore) rename = (_name_=cog));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;the variable cog in the Longcog data set is character as _name_ is character.&lt;/P&gt;
&lt;P&gt;Also the numeric values would likely be in Cogscore, not Cog1, Cog2, Cog3 as you transposed them into Cogscore.&lt;/P&gt;
&lt;P&gt;So when you go to this step you have no variables to assign values to cog. If there were they would be attempting to go into character value.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;data longcog2;
set longcog;
cog=cog1; time=1; output;
cog=cog2; time=2; output;
cog=cog3; time=3; output;
cog=cog4; time=4; output;
cog=cog5; time=5; output;
cog=cog6; time=6; output;
keep HHIDPN SSRI time cog;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 30 Jan 2024 13:39:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-help-transposing-longitudinal-data-HRS-and-creation-of-time/m-p/913578#M360068</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2024-01-30T13:39:32Z</dc:date>
    </item>
    <item>
      <title>Re: Need help transposing longitudinal data (HRS) and creation of time variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-help-transposing-longitudinal-data-HRS-and-creation-of-time/m-p/913591#M360078</link>
      <description>&lt;P&gt;I guess you want this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data longcog2;
set longcog;
time = input(substr(cog,4),best.);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 30 Jan 2024 15:04:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-help-transposing-longitudinal-data-HRS-and-creation-of-time/m-p/913591#M360078</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2024-01-30T15:04:54Z</dc:date>
    </item>
  </channel>
</rss>

