<?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 create this variable? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-this-variable/m-p/469578#M120149</link>
    <description>&lt;P&gt;I tried it like this but it didnt work &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;&lt;P&gt;What did I do wrong? Can you please tell me?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%data2datastep(drugs, drugs_new, uniquedrugs);&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 12 Jun 2018 11:10:41 GMT</pubDate>
    <dc:creator>marysmith</dc:creator>
    <dc:date>2018-06-12T11:10:41Z</dc:date>
    <item>
      <title>How to create this variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-this-variable/m-p/469546#M120137</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data arzneimittelgruppen; 
set datensatz_1416_Erstanzeige;
if NIS_Nummer in (6513,6699) then allergy=1; /*N=2*/
if NIS_Nummer in (2047,6613,6623,6725,7030) then antibiotics=1; /*N=5*/
if NIS_Nummer in (3203,6622,6629,6649,6818,6819) then antidiabetic=1; /*N=6*/
if NIS_Nummer in (6653,6736,6771,6775,6837,6847) then antihypertensive=1;  /*N=5*/
if NIS_Nummer in (2407,2507,2532,3396,6635) then antipsychotic=1;  /*N=5*/
if NIS_Nummer in (2069,5266,6131,6703,6719) then antivirals=1; /*?*/ /*N=5*/
if NIS_Nummer in (2046,2289,6468,6626,6711) then biologicals=1; /*N=5*/
if NIS_Nummer in (2230,6709) then contrast=1; /*N=2*/
if NIS_Nummer in (2268,2552,2962,6657,6713,6799) then copd=1; /*N=6*/
if NIS_Nummer in (1851,1856,1969,1990,6194,6521,6784,6849,6880) then dermatology=1; /*N=9*/
if NIS_Nummer in (2087,2311,2590,3431,5080,6417,6419,6611,6618,6625,6652,6666,6673,6677,6683,6696,6720,6721,6815,6857,6858,6870,6876,6877,6878,6884) then registry=1;/*N=26*/
if NIS_Nummer in (2187,6170,6172,6752,6883) then eye=1; /*N=5*/
if NIS_Nummer in (2367,2408,2548,2568,3377,3387,6431,6474,6530,6534,6535,6536,6627,6642,6660,6661,6665,6668,6698,6759,6847,6869,6874,7038) then haematology=1; /*N=24*/
if NIS_Nummer in (1867,3432,4147,6663,6717,6755,6758,6766,6835) then hormone=1;    /*N=9*/
if NIS_Nummer in (1928,1949,2067,2075,2147,2211,2631,2632,5383,6449,6494,6532,6636,6640,6714,6772) then neurological=1; /*N=16*/
if NIS_Nummer in (2188) then nondrug=1; /*N=1*/
if NIS_Nummer in (1888,2027,2309,2314,2467,2527,2837,2980,3186,3612,4685,5451,5584,6471,6507,6637,6659,6669,6682,6694,6710,6735,6741,6773,6862,6889)then nonpres=1;  /*N=26*/
if NIS_Nummer in (1906,1908,1955,2071,2076,2090,2155,2307,2628,2630,2892,3039,3078,3806,4056,4306,5394,6173,6473,6501,6506,6509,6512,6519,6520,6523,6524,6526,6529,6531,
6612,6630,6638,6639,6646,6651,6655,6656,6658,6670,6671,6675,6685,6687,6690,6691,6716,6738,6762,6764,6765,6774,6779,6780,6788,6789,6791,6795,6804,6816,6830,6832,6841,
6868,6872,6873,6879,7036) then oncology=1;         /*N=69*/
if NIS_Nummer in (2228,2269,6609) then orphan=1; /*N=3*/
if NIS_Nummer in (2095,2529,2549,2707,5361,5508,6643,6645,6667,6679,6724,6728,6756,6801,6828,6856,6861,6887) then others=1; /*N=18*/
if NIS_Nummer in (1988,6518,6654,6740,6777,6782,6806,6831,6863,7037)then pain=1; /*N=10*/
if NIS_Nummer in (2389,2608,3598,3774,3820,6751)then urologics=1;  /*N=6*/
run;


data drugs1;
set datensatz_1416_Erstanzeige;
if NIS_Nummer=1847 then drug="Imnovid";
if NIS_Nummer=1851 then drug="Actikerall II";
if NIS_Nummer=1856 then drug="Iluvien";
if NIS_Nummer=1867 then drug="Leuprone HEXAL";
if NIS_Nummer=1888 then drug="Angocin";
if NIS_Nummer=1906 then drug="Gemedac";
if NIS_Nummer=1908 then drug="Taxceus";
if NIS_Nummer=1928 then drug="Botox";
if NIS_Nummer=1949 then drug="Azilect";
if NIS_Nummer=1955 then drug="Giotrif";
if NIS_Nummer=1969 then drug="Monovo Emulsion ";
if NIS_Nummer=1969 then drug2="Xamiol Gel ";
if NIS_Nummer=1969 then drug3="Daivobet Gel";
if NIS_Nummer=1988 then drug="Naropin";
if NIS_Nummer=1990 then drug="Deximune";
if NIS_Nummer=2027 then drug="Grippostad C";
if NIS_Nummer=2046 then drug="Extavia";
run;


&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Dear community,&lt;/P&gt;&lt;P&gt;im stuck again and dont know how to write this command.&lt;/P&gt;&lt;P&gt;I have a data set with different clinical trials of pharmaceuticals. Each trial has a NIS Number and sometimes there was only one drug that was tested, some trials tested up to 8 different drugs.&lt;/P&gt;&lt;P&gt;Now I want to create a new variable, called "unique drugs". I need to know how many different drugs were tested.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example:&lt;/P&gt;&lt;P&gt;Trial No. 1 Nis_Number=1234, drug = ASS&lt;/P&gt;&lt;P&gt;Trial No.2 Nis_Number=1235, drug= ibuprofen, drug2=Paracetamol&lt;/P&gt;&lt;P&gt;Trial No.3 Nis_Number=1236, drug=.&lt;/P&gt;&lt;P&gt;trial No. 4 Nis_Number=1237, drug=Apixaban, drug2=Eliquis, drug3=Ibuprofen, drug4=Brillique, drug5=ASS&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How can I count the amount of unique drugs?&lt;/P&gt;&lt;P&gt;E.g. I want to know how many Trials tested ASS and how many trials was Ibuprofen tested.&lt;/P&gt;&lt;P&gt;Thank you so much in advance&lt;/P&gt;</description>
      <pubDate>Tue, 12 Jun 2018 10:08:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-this-variable/m-p/469546#M120137</guid>
      <dc:creator>marysmith</dc:creator>
      <dc:date>2018-06-12T10:08:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to create this variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-this-variable/m-p/469550#M120140</link>
      <description>&lt;P&gt;Transpose the data set to a long format, so you have only one drug variable, and then use count(distinct()).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For code, post a data step of your dataset - see my footnotes.&lt;/P&gt;</description>
      <pubDate>Tue, 12 Jun 2018 10:06:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-this-variable/m-p/469550#M120140</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-06-12T10:06:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to create this variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-this-variable/m-p/469551#M120141</link>
      <description>&lt;P&gt;Thank you again for your quick replay! Unfortuantely I dont know how to transpose the data set to a long format &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt; Can you help me with this? &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 12 Jun 2018 10:09:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-this-variable/m-p/469551#M120141</guid>
      <dc:creator>marysmith</dc:creator>
      <dc:date>2018-06-12T10:09:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to create this variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-this-variable/m-p/469552#M120142</link>
      <description>&lt;P&gt;See the second line of my response.&lt;/P&gt;</description>
      <pubDate>Tue, 12 Jun 2018 10:10:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-this-variable/m-p/469552#M120142</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-06-12T10:10:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to create this variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-this-variable/m-p/469554#M120144</link>
      <description>Okay thank you I will try this!&lt;BR /&gt;</description>
      <pubDate>Tue, 12 Jun 2018 10:13:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-this-variable/m-p/469554#M120144</guid>
      <dc:creator>marysmith</dc:creator>
      <dc:date>2018-06-12T10:13:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to create this variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-this-variable/m-p/469578#M120149</link>
      <description>&lt;P&gt;I tried it like this but it didnt work &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;&lt;P&gt;What did I do wrong? Can you please tell me?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%data2datastep(drugs, drugs_new, uniquedrugs);&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 12 Jun 2018 11:10:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-this-variable/m-p/469578#M120149</guid>
      <dc:creator>marysmith</dc:creator>
      <dc:date>2018-06-12T11:10:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to create this variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-this-variable/m-p/469654#M120177</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/185853"&gt;@marysmith&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Unfortunately, I have never seen or used that &lt;STRONG&gt;data2datastep&lt;/STRONG&gt; macro yet. But your macro call (the RUN statement is unnecessary) would imply that you have a &lt;EM&gt;dataset&lt;/EM&gt; named &lt;STRONG&gt;drugs&lt;/STRONG&gt; in a &lt;EM&gt;library&lt;/EM&gt; named &lt;STRONG&gt;drugs_new&lt;/STRONG&gt; and you want to create an &lt;EM&gt;external file&lt;/EM&gt; named &lt;STRONG&gt;uniquedrugs&lt;/STRONG&gt; (presumably without a suffix such as .txt) containing SAS code for creating a copy of dataset&amp;nbsp;&lt;STRONG&gt;drugs_new.drugs&lt;/STRONG&gt;.&lt;BR /&gt;Maybe that's not what you really want.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can you please be more specific what you mean by "it didn't work"? Error messages in the log will be helpful to understand what went wrong.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As to your initial post, you are asking two different questions:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;You want to count unique drugs. Is this &lt;EM&gt;within&lt;/EM&gt; a trial, so that, in your example, the new variable &lt;STRONG&gt;unique_drugs&lt;/STRONG&gt; should receive values 1, 2, 0 and 5, respectively, for trials 1, 2, 3 and 4?&amp;nbsp;Or is it &lt;EM&gt;across&lt;/EM&gt; trials?&lt;/LI&gt;
&lt;LI&gt;You want to count trials involving specific drugs.&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The simplified code example below demonstrates (part of) what&amp;nbsp;you can do with the "transpose" and "count(distinct ...)" techniques&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;suggested.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Create test data */

data have;
input trial NIS_Nummer drug $ drug2 $ drug3 $;
cards;
1 1234 ABC DEF ABC
2 1235 CCC DDD EEE
3 1236 DEF .   .
4 1237 .   .   .
5 1238 CCC DEF .
;

/* Transpose to a long format */

proc transpose data=have out=long(rename=(col1=drug));
by trial NIS_Nummer;
var drug:;
run;

/* Count unique drugs per trial */

proc sql;
select trial, NIS_Nummer, count(distinct drug) as unique_drugs
from long
group by trial, NIS_Nummer;
quit;

/* Count unique trials per drug */

proc sql;
select drug, count(distinct trial) as trials
from long
where drug ne ' '
group by drug;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Caveat: When it comes to counting "unique drugs", you are probably aware of the many issues which can arise if drug names in your data are not standardized (typos, upper/lower case, abbreviations, trade names vs. generic vs. substance names, ...) or missing values are denoted differently ("n/a", &lt;EM&gt;blank&lt;/EM&gt;, ...).&lt;/P&gt;</description>
      <pubDate>Tue, 12 Jun 2018 15:39:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-this-variable/m-p/469654#M120177</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2018-06-12T15:39:46Z</dc:date>
    </item>
    <item>
      <title>Re: How to create this variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-this-variable/m-p/469841#M120225</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/185853"&gt;@marysmith&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I tried it like this but it didnt work &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;What did I do wrong? Can you please tell me?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%data2datastep(drugs, drugs_new, uniquedrugs);&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;When something "does not work", always post the log.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The macro accepts up to 4 positional parameters:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;dataset name within the library - required&lt;/LI&gt;
&lt;LI&gt;library name - optional (if none given, will default to WORK)&lt;/LI&gt;
&lt;LI&gt;&lt;EM&gt;fully qualified&lt;/EM&gt; filename of file to be created - optional. Default is "create_&amp;amp;lib._&amp;amp;dsn._data.sas" in current working directory.&lt;/LI&gt;
&lt;LI&gt;number of observations - optional&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;Since you specified no path for the output file, the macro probably tried to write to a location where you don't have write permission.&lt;/P&gt;
&lt;P&gt;In case of SAS UE, I'd use a filename like /folders/myfolder/create_dataset.sas. After this is created, you can pick it up from the Windows/Linux/MacOS side with any text editor and copy/paste the contents here.&lt;/P&gt;</description>
      <pubDate>Wed, 13 Jun 2018 07:07:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-this-variable/m-p/469841#M120225</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-06-13T07:07:06Z</dc:date>
    </item>
  </channel>
</rss>

