<?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: Creating a variable that gets the names of drugs in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-variable-that-gets-the-names-of-drugs/m-p/689784#M209709</link>
    <description>Are you actually using names such as 'drug1' or is that an actual name that you'd like to be interpretable?&lt;BR /&gt;&lt;BR /&gt;</description>
    <pubDate>Thu, 08 Oct 2020 00:28:11 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2020-10-08T00:28:11Z</dc:date>
    <item>
      <title>Creating a variable that gets the names of drugs</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-variable-that-gets-the-names-of-drugs/m-p/689771#M209704</link>
      <description>&lt;P&gt;I have 40 variables (Drug1-40) with data in them being either 1 (drug given) or 0 (not given) or . (missing). I have created a variable NumofRx that sums up presence of a drug (sum(drug1--drug40)) for individual patient. The range of NumofRx is from 0 to 10, I would like to create a variable where I want to see what drugs ( drug1 or drug6 or drug 13 ...) comes under numofrx=2 ,&amp;nbsp;numofrx=3 ......numofrx=10.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sample data:&lt;/P&gt;&lt;P&gt;Data pattern;&lt;/P&gt;&lt;P&gt;infile datalines;&lt;BR /&gt;input id year drug1 drug2 drug3 drug4 numofrx ;&lt;BR /&gt;datalines;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1 2000&amp;nbsp; &amp;nbsp;1 0 1 0 2&lt;/P&gt;&lt;P&gt;2 2005&amp;nbsp; 1&amp;nbsp;0 0 0 1&lt;/P&gt;&lt;P&gt;3 2006&amp;nbsp; 0 1&amp;nbsp;1 1 3&lt;/P&gt;&lt;P&gt;4 2005 0&amp;nbsp;0 1 0 1&lt;/P&gt;&lt;P&gt;5 2005&amp;nbsp; 0 1&amp;nbsp;1 0 2&lt;/P&gt;&lt;P&gt;6 2006&amp;nbsp; 1&amp;nbsp;0 1 0 2&lt;/P&gt;&lt;P&gt;7 2000 .&amp;nbsp;0 1 0 1&lt;/P&gt;&lt;P&gt;8 2000&amp;nbsp; 0&amp;nbsp;0 0&amp;nbsp; 0&lt;/P&gt;&lt;P&gt;9 2001 1&amp;nbsp;1 1 1 4&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to have a dataset/table that looks like below&lt;/P&gt;&lt;P&gt;ID Numofrx&amp;nbsp; &amp;nbsp;Drugs&amp;nbsp;&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;drug1+drug3&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;drug1&lt;/P&gt;&lt;P&gt;3&amp;nbsp; &amp;nbsp; &amp;nbsp; 3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;drug2+drug3+drug4&lt;/P&gt;&lt;P&gt;4&amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;drug1&lt;/P&gt;&lt;P&gt;5&amp;nbsp; &amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;drug2+drug3&lt;/P&gt;&lt;P&gt;6&amp;nbsp; &amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;drug1+drug3&lt;/P&gt;&lt;P&gt;7&amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; drug3&lt;/P&gt;&lt;P&gt;8&amp;nbsp; &amp;nbsp; &amp;nbsp; 0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&lt;/P&gt;&lt;P&gt;9&amp;nbsp; &amp;nbsp; &amp;nbsp; 4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;drug1+drug2+drug3+drug4&lt;/P&gt;</description>
      <pubDate>Wed, 07 Oct 2020 23:19:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-variable-that-gets-the-names-of-drugs/m-p/689771#M209704</guid>
      <dc:creator>ihtishamsultan</dc:creator>
      <dc:date>2020-10-07T23:19:06Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a variable that gets the names of drugs</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-variable-that-gets-the-names-of-drugs/m-p/689777#M209708</link>
      <description>&lt;P&gt;I think this should do it:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data pattern;
	infile datalines	MISSOVER;
	input ID year drug1 drug2 drug3 drug4 NumOfRx ;
datalines;
1 2000   1 0 1 0 2
2 2005  1 0 0 0 1
3 2006  0 1 1 1 3
4 2005 0 0 1 0 1
5 2005  0 1 1 0 2
6 2006  1 0 1 0 2
7 2000 . 0 1 0 1
8 2000  0 0 0 0 
9 2001 1 1 1 1 4
;
RUN;

DATA	Pattern_Details	(KEEP=ID NumOfRx Drugs);
	DROP	_i;

	SET	Pattern;
	ARRAY	Drug	[*]	Drug1 - Drug4;

	LENGTH	Drugs	$256;

	IF	MISSING(NumOfRx)	THEN
		NumOfRx		=	0;

	DO	_i			=	1	TO	DIM(Drug);
		IF	Drug[_i]		THEN
			Drugs	=	CATS(Drugs, '+Drug', _i);
	END;

	Drugs			=	SUBSTR(Drugs, 2);
RUN;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Jim&lt;/P&gt;</description>
      <pubDate>Thu, 08 Oct 2020 00:11:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-variable-that-gets-the-names-of-drugs/m-p/689777#M209708</guid>
      <dc:creator>jimbarbour</dc:creator>
      <dc:date>2020-10-08T00:11:51Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a variable that gets the names of drugs</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-variable-that-gets-the-names-of-drugs/m-p/689784#M209709</link>
      <description>Are you actually using names such as 'drug1' or is that an actual name that you'd like to be interpretable?&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 08 Oct 2020 00:28:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-variable-that-gets-the-names-of-drugs/m-p/689784#M209709</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-10-08T00:28:11Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a variable that gets the names of drugs</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-variable-that-gets-the-names-of-drugs/m-p/689885#M209766</link>
      <description>&lt;P&gt;As usual when there is a series of variables containing the basically same information, moving data from structure to content by transposing makes the job easier:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data pattern;
infile datalines;
input id year drug1 drug2 drug3 drug4;
datalines;
1 2000   1 0 1 0
2 2005  1 0 0 0
3 2006  0 1 1 1
4 2005 0 0 1 0
5 2005  0 1 1 0
6 2006  1 0 1 0
7 2000 . 0 1 0
8 2000  0 0 0 .
9 2001 1 1 1 1 
;

proc transpose
  data=pattern
  out=long (rename=(_name_=drug col1=yn))
;
by id;
var drug:;
run;

data want;
set long;
length numofrx 8 drugs $100;
retain numofrx drugs;
by id;
if first.id
then do;
  drugs = "";
  numofrx = 0;
end;
if yn
then do;
  drugs = catx('+',drugs,drug);
  numofrx + 1;
end;
if last.id;
keep id numofrx drugs;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 08 Oct 2020 07:43:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-variable-that-gets-the-names-of-drugs/m-p/689885#M209766</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-10-08T07:43:06Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a variable that gets the names of drugs</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-variable-that-gets-the-names-of-drugs/m-p/690060#M209857</link>
      <description>There are labels for each drug, would it be possible to have the names?</description>
      <pubDate>Thu, 08 Oct 2020 15:41:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-variable-that-gets-the-names-of-drugs/m-p/690060#M209857</guid>
      <dc:creator>ihtishamsultan</dc:creator>
      <dc:date>2020-10-08T15:41:39Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a variable that gets the names of drugs</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-variable-that-gets-the-names-of-drugs/m-p/690066#M209860</link>
      <description>&lt;P&gt;Yes.&amp;nbsp; That's fairly easy using the VLABEL function.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Change the code as follows:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA	Pattern_Details	(KEEP=ID NumOfRx Drugs);
	DROP	_i;

	SET	Pattern;
	ARRAY	Drug	[*]	Drug1 - Drug4;

	LENGTH	Drugs	$256;

	IF	MISSING(NumOfRx)	THEN
		NumOfRx		=	0;

	DO	_i			=	1	TO	DIM(Drug);
		IF	Drug[_i]		THEN
			Drugs	=	CATS(Drugs, '+', VLABEL(Drug[_i]), _i);
	END;

	Drugs			=	SUBSTR(Drugs, 2);
RUN;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Jim&lt;/P&gt;</description>
      <pubDate>Thu, 08 Oct 2020 15:50:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-variable-that-gets-the-names-of-drugs/m-p/690066#M209860</guid>
      <dc:creator>jimbarbour</dc:creator>
      <dc:date>2020-10-08T15:50:47Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a variable that gets the names of drugs</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-variable-that-gets-the-names-of-drugs/m-p/690084#M209872</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/235318"&gt;@ihtishamsultan&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;There are labels for each drug, would it be possible to have the names?&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Use the LABEL= option in the PROC TRANSPOSE statement.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 08 Oct 2020 16:21:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-variable-that-gets-the-names-of-drugs/m-p/690084#M209872</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-10-08T16:21:19Z</dc:date>
    </item>
  </channel>
</rss>

