<?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: Data reformatting question in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Data-reformatting-question/m-p/833951#M35822</link>
    <description>Thank you mkeintz! I will definitely try it out as soon as I am in the office (where SAS is available) Monday! Have a great weekend!</description>
    <pubDate>Sat, 17 Sep 2022 06:12:10 GMT</pubDate>
    <dc:creator>hellorc</dc:creator>
    <dc:date>2022-09-17T06:12:10Z</dc:date>
    <item>
      <title>Data reformatting question</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Data-reformatting-question/m-p/833946#M35820</link>
      <description>&lt;P&gt;closed&lt;/P&gt;</description>
      <pubDate>Sat, 17 Sep 2022 16:16:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Data-reformatting-question/m-p/833946#M35820</guid>
      <dc:creator>hellorc</dc:creator>
      <dc:date>2022-09-17T16:16:33Z</dc:date>
    </item>
    <item>
      <title>Re: Data reformatting question</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Data-reformatting-question/m-p/833950#M35821</link>
      <description>&lt;P&gt;The approach here is to build a 52-element array of nursing home values for each id, possibly requiring reading in multiple observation per id.&amp;nbsp; That what the&amp;nbsp; "do until (last.id)" loop below does, containing a "set have" statement inside it:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input id age sex $ nursing_home_id covid covid_date :yymmdd10. week1-week52 ;
format covid_date yymmdd10.;
datalines;
1 75 M 0769 1 2021/12/30 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1
1 75 M 1650 0 . 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
1 75 M 3382 0 . 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0
run;

data want (keep=id age sex nursing_home_id covid week);
  do until (last.id);
    set have (rename=(covid=covid_dummy));
    by id;

    array weeks {52} week1-week52;
    array nh    {52} ;

    do w=1 to 52;
      if weeks{w}=1 then nh{w}=nursing_home_id;
    end;

    if covid_date^=. then do;
      covid_week=ceil((covid_date-'31dec2020'd)/7);
      if covid_week=53 then covid_week=52;
    end;
  end;

  do week=1 to 52;
    if week=covid_week then covid=1;
    else covid=0;
    nursing_home_id=nh{week};
    output;
  end;
run;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And thanks for submitting a "workable" data step (I had to make a couple minor changes to the DATA HAVE step).&amp;nbsp; So I can say this code has been tested.&lt;/P&gt;</description>
      <pubDate>Sat, 17 Sep 2022 05:32:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Data-reformatting-question/m-p/833950#M35821</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2022-09-17T05:32:42Z</dc:date>
    </item>
    <item>
      <title>Re: Data reformatting question</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Data-reformatting-question/m-p/833951#M35822</link>
      <description>Thank you mkeintz! I will definitely try it out as soon as I am in the office (where SAS is available) Monday! Have a great weekend!</description>
      <pubDate>Sat, 17 Sep 2022 06:12:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Data-reformatting-question/m-p/833951#M35822</guid>
      <dc:creator>hellorc</dc:creator>
      <dc:date>2022-09-17T06:12:10Z</dc:date>
    </item>
    <item>
      <title>Re: Data reformatting question</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Data-reformatting-question/m-p/833963#M35823</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input id age sex $ nursing_home_id covid covid_date :yymmdd10. week1-week52 ;
format covid_date yymmdd10.;
datalines;
1 75 M 0769 1 2021/12/30 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1
1 75 M 1650 0 . 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
1 75 M 3382 0 . 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0
;

data temp;
 set have;
 array x{*} week1-week52;
  w=week(covid_date,'w');
  flag=0;
 do week=1 to dim(x);
  v=x{week};
  if w=week then flag=1;
  if v then output;
 end;
keep id age sex nursing_home_id flag week;
run;
proc sort data=temp out=want;
by id age sex week;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 17 Sep 2022 10:31:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Data-reformatting-question/m-p/833963#M35823</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2022-09-17T10:31:54Z</dc:date>
    </item>
  </channel>
</rss>

