<?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: How to rearrange range of medication start dates and corresponding end-dates to startdate1-x? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-rearrange-range-of-medication-start-dates-and/m-p/869385#M343391</link>
    <description>&lt;P&gt;Thank you Reeza! I am having difficulties creating the code for transposing to long and get the drugdates into a single column. Would it be possible for you to share some code on how to transpose it and how to use VNAME to get the drug names into a separate column? Thanks in advance!&lt;/P&gt;</description>
    <pubDate>Wed, 12 Apr 2023 10:38:22 GMT</pubDate>
    <dc:creator>mlas</dc:creator>
    <dc:date>2023-04-12T10:38:22Z</dc:date>
    <item>
      <title>How to rearrange range of medication start dates and corresponding end-dates to startdate1-x?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-rearrange-range-of-medication-start-dates-and/m-p/869213#M343358</link>
      <description>&lt;P&gt;Hi guys,&lt;/P&gt;&lt;P&gt;I have a dataset of medication pick-up dates for a list of patients that I am trying to reformat. There are a total of 4 different drugs in the dataset. Each line is a unique person (key variable = id), each time they pick up a new drug at the pharmacy a new drugX_startdate and a corresponding drugX_enddate is added in wide format to the dataset. Sometimes the drug periods overlap (e.g. drugB_startdate1 is before drugA_enddate1). Most of the patients are only on one of the 4 drugs and will just have missing data on the other drugs. I want to get rid of the drug names and just get them all sorted as drug_start1-etc drug_end1-etc such that all patients in the dataset have a drug_start1 corresponding to whichever drug they start on. It varies from 0 to 45 on the number of pick-ups for any of the 4 drugs.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The dataset is currently in the format:&lt;/P&gt;&lt;P&gt;id drugA_start1&amp;nbsp;drugA_start2&amp;nbsp;drugA_start3 drugA_end1&amp;nbsp;drugA_end2&amp;nbsp;drugA_end3 drugB_start1 drugB_end1 etc&lt;/P&gt;&lt;P&gt;1. &amp;nbsp;01JAN2000 &amp;nbsp;01FEB2000 &amp;nbsp;01MAR2000 &amp;nbsp;10JAN2000 &amp;nbsp;10FEB2000 18MAR2000 02APR2000 &amp;nbsp; 20APR2000&lt;/P&gt;&lt;P&gt;2. &amp;nbsp;01AUG2001 &amp;nbsp;01SEP2001 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; . &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;20AUG2001 &amp;nbsp;18SEP2001 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; . &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;01JAN2001 &amp;nbsp; 31JAN2001&lt;/P&gt;&lt;P&gt;3. &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; &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; &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; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;. &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;01JAN2002 &amp;nbsp; 15FEB2002&lt;/P&gt;&lt;P&gt;4. &amp;nbsp;01JAN2003 &amp;nbsp;01FEB2003 &amp;nbsp;01MAR2003 &amp;nbsp;10JAN2003 &amp;nbsp;10FEB2003 18MAR2003 &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;Only there are many more startdates and enddates for each drug and there are a total of 4 different drugs.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to reformat the dataset into the following chronological order and get rid of the drug-specific prefix but such that drug_stat(x) still corresponds to drug_end(x):&lt;/P&gt;&lt;P&gt;id &amp;nbsp; drug_start1 &amp;nbsp; drug_start2 &amp;nbsp; drug_start3 &amp;nbsp; drug_start4 &amp;nbsp;(etc) drug_end1 &amp;nbsp;drug_end2 &amp;nbsp; drug_end3 &amp;nbsp; drug_end4 (etc)&lt;/P&gt;&lt;P&gt;1. &amp;nbsp;01JAN2000 &amp;nbsp;01FEB2000 &amp;nbsp;01MAR2000 &amp;nbsp;02APR2000 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;10JAN2000 10FEB2000&amp;nbsp;18MAR2000 20APR2000&lt;/P&gt;&lt;P&gt;2. &amp;nbsp;01JAN2001 &amp;nbsp;01AUG2001&amp;nbsp; 01SEP2001 &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; 31JAN2001 20AUG2001&amp;nbsp;18SEP2001 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;. &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;3. &amp;nbsp;01JAN2002 &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;. &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; &amp;nbsp; &amp;nbsp; 15FEB2001 &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; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .&lt;/P&gt;&lt;P&gt;4. &amp;nbsp;01JAN2003 &amp;nbsp;01FEB2003 &amp;nbsp;01MAR2003 &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; 10JAN2003 &amp;nbsp;10FEB2003 &amp;nbsp;18MAR2003 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I hope this makes sense &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; In the end I need to calculate the proportion of time on any medication as the number of days on medication/total days in period which is why I need the data like this. Can anyone give me some guidance on how to reformat the data like this? Thanks in advance!&lt;/P&gt;</description>
      <pubDate>Tue, 11 Apr 2023 21:16:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-rearrange-range-of-medication-start-dates-and/m-p/869213#M343358</guid>
      <dc:creator>mlas</dc:creator>
      <dc:date>2023-04-11T21:16:56Z</dc:date>
    </item>
    <item>
      <title>Re: How to rearrange range of medication start dates and corresponding end-dates to startdate1-x?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-rearrange-range-of-medication-start-dates-and/m-p/869217#M343359</link>
      <description>Change your data structure to a long format, order as desired and then if you really want (do not recommend) reflip it to a wide format again. &lt;BR /&gt;&lt;BR /&gt;Format recommended:&lt;BR /&gt;&lt;BR /&gt;ID DRUG StartDate EndDate&lt;BR /&gt;&lt;BR /&gt;I would recommend a data step transpose in this case. &lt;BR /&gt;&lt;A href="https://stats.oarc.ucla.edu/sas/modules/reshaping-data-wide-to-long-using-a-data-step/" target="_blank"&gt;https://stats.oarc.ucla.edu/sas/modules/reshaping-data-wide-to-long-using-a-data-step/&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;Use the VNAME function to get the variable names/drug information. &lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 11 Apr 2023 21:50:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-rearrange-range-of-medication-start-dates-and/m-p/869217#M343359</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2023-04-11T21:50:34Z</dc:date>
    </item>
    <item>
      <title>Re: How to rearrange range of medication start dates and corresponding end-dates to startdate1-x?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-rearrange-range-of-medication-start-dates-and/m-p/869385#M343391</link>
      <description>&lt;P&gt;Thank you Reeza! I am having difficulties creating the code for transposing to long and get the drugdates into a single column. Would it be possible for you to share some code on how to transpose it and how to use VNAME to get the drug names into a separate column? Thanks in advance!&lt;/P&gt;</description>
      <pubDate>Wed, 12 Apr 2023 10:38:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-rearrange-range-of-medication-start-dates-and/m-p/869385#M343391</guid>
      <dc:creator>mlas</dc:creator>
      <dc:date>2023-04-12T10:38:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to rearrange range of medication start dates and corresponding end-dates to startdate1-x?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-rearrange-range-of-medication-start-dates-and/m-p/869425#M343405</link>
      <description>&lt;P&gt;In the future please show what you've tried.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data wide;
	set have;
	array _start(*) drugA_start: drugB_start:;
	array _end(*) drugA_end: drugB_end:;

	do i=1 to dim(_start);
		start_date=_start(i);
		end_date=_end(i);
		Drug=scan(vname(_start(i)), 1, '_');
		output;
		*conditionally output for non misisng but you need to check your data quality;
		*if nmiss(start_date, end_date) = 0 then output;
	end;
	keep ID drug start_date end_date;
	format start_date end_date date9.;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 12 Apr 2023 15:39:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-rearrange-range-of-medication-start-dates-and/m-p/869425#M343405</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2023-04-12T15:39:03Z</dc:date>
    </item>
  </channel>
</rss>

