<?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: %LET macro statement in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/LET-macro-statement/m-p/495511#M130784</link>
    <description>&lt;P&gt;Fastest way might be use some code generation to generate an SQL statement to summarize by ID.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data symptoms;
  input id symptom $32. ;
cards;
1 discharge
2 pain
3 sore
4 odor
4 warts
;

proc sort data=symptoms(keep=symptom) nodupkey out=symptomlist ;
  by symptom;
run;

filename code temp;
data _null_;
  set symptomlist end=eof;
  file code ;
  if _n_=1 then put
 'proc sql noprint;'
/'create table want as select'
/' id'
  ;
  put ',max(symptom=' symptom :$quote. ') as ' symptom  ;
  if eof then put
 'from symptoms'
/'group by id'
/';'
/'quit;'
  ;
run;

%include code / source2;
proc print;
run;&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;Obs    id    discharge    odor    pain    sore    warts

 1      1        1          0       0       0       0
 2      2        0          0       1       0       0
 3      3        0          0       0       1       0
 4      4        0          1       0       0       1&lt;/PRE&gt;
&lt;PRE&gt;137 +proc sql noprint;
138 +create table want as select
139 + id
140 +,max(symptom="discharge" ) as discharge
141 +,max(symptom="odor" ) as odor
142 +,max(symptom="pain" ) as pain
143 +,max(symptom="sore" ) as sore
144 +,max(symptom="warts" ) as warts
145 +from symptoms
146 +group by id
147 +;
NOTE: SAS threaded sort was used.
NOTE: Table WORK.WANT created, with 4 rows and 6 columns.&lt;/PRE&gt;
&lt;P&gt;If your source data is NOT one observation per ID*SYMPTOM then you would need to change the logic of the test for whether a particular observation has an indication of that symptom.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also if your symptom values are not valid SAS variable names then you will have trouble.&amp;nbsp; You might need to generate unique names for the flag variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 13 Sep 2018 20:44:35 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2018-09-13T20:44:35Z</dc:date>
    <item>
      <title>%LET macro statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/LET-macro-statement/m-p/495472#M130764</link>
      <description>&lt;P&gt;Hi I have a data like this;&lt;/P&gt;&lt;P&gt;data symptoms;&lt;/P&gt;&lt;P&gt;input id symptoms $ ;&lt;/P&gt;&lt;P&gt;cards;&lt;/P&gt;&lt;P&gt;1 discharge&lt;/P&gt;&lt;P&gt;2 pain&lt;/P&gt;&lt;P&gt;3 sore&lt;/P&gt;&lt;P&gt;4 odor warts&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I transposed the data set and it looks this now&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;id&amp;nbsp; discharge&amp;nbsp; pain&amp;nbsp; sore&amp;nbsp; odor&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1&amp;nbsp; discharge&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; pain&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; odor&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; sore&lt;/P&gt;&lt;P&gt;4&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; odor&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;instead of this i would like to have like THIS (below)&lt;/P&gt;&lt;P&gt;id&amp;nbsp; discharge&amp;nbsp; pain&amp;nbsp; sore&amp;nbsp; odor&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/P&gt;&lt;P&gt;3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&lt;/P&gt;&lt;P&gt;4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;&lt;P&gt;I used if then statement like this;&lt;/P&gt;&lt;P&gt;if discharge ="discharge" then discharge="1";&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;but i have hundreds of symptoms to write if then statement.&amp;nbsp; is there a shorter way macro or something to do it efficiently?&lt;/P&gt;</description>
      <pubDate>Thu, 13 Sep 2018 19:31:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/LET-macro-statement/m-p/495472#M130764</guid>
      <dc:creator>Dhana18</dc:creator>
      <dc:date>2018-09-13T19:31:27Z</dc:date>
    </item>
    <item>
      <title>Re: %LET macro statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/LET-macro-statement/m-p/495475#M130766</link>
      <description>&lt;P&gt;if you are OK with auto conversion log note:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data have;
input (id  discharge  pain  sore  odor  ) (:$10.);
cards;
1  discharge . . . 
2         .           pain      .        odor
3            . .                sore .
4                  . . .                      odor
;

data want;
set have;
array t(*) discharge--odor;
do _n_=1 to dim(t);
t(_n_)= vname(t(_n_))=t(_n_);
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 13 Sep 2018 19:36:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/LET-macro-statement/m-p/495475#M130766</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-09-13T19:36:46Z</dc:date>
    </item>
    <item>
      <title>Re: %LET macro statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/LET-macro-statement/m-p/495478#M130767</link>
      <description>&lt;P&gt;Regardless of the route you choose, macro language will not be involved.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One possibility:&amp;nbsp; add a dummy variable with a value of 1:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data have2;&lt;/P&gt;
&lt;P&gt;set have;&lt;/P&gt;
&lt;P&gt;dummy=1;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then you can use that in your transposing:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc transpose data=have2 out=want;&lt;/P&gt;
&lt;P&gt;var dummy;&lt;/P&gt;
&lt;P&gt;id symptoms;&lt;/P&gt;
&lt;P&gt;by id;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Issues you will need to address beyond that:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;This fills in the "1" values only, not the "0" values.&amp;nbsp; You will still need to go back and change missing values to 0.&amp;nbsp; That's a straightforward application for arrays.&lt;/LI&gt;
&lt;LI&gt;If the variable SYMPTOMS really can contain a list rather than a single item, you will need to split it up.&amp;nbsp; For example, for ID=4, you will need to change it to two observations instead of 1.&amp;nbsp; One observation will have symtpoms="warts" and the other will have symptoms="odor".&lt;/LI&gt;
&lt;LI&gt;It is entirely likely that the transposed data will be clumsy and difficult to work with.&amp;nbsp; You might be better served by never doing this at all.&amp;nbsp; But that really depends on where the analysis is&amp;nbsp;headed down the road.&lt;/LI&gt;
&lt;/UL&gt;</description>
      <pubDate>Thu, 13 Sep 2018 19:39:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/LET-macro-statement/m-p/495478#M130767</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-09-13T19:39:01Z</dc:date>
    </item>
    <item>
      <title>Re: %LET macro statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/LET-macro-statement/m-p/495481#M130770</link>
      <description>&lt;P&gt;Set a dummy variable and then you can use that as var in transpose.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
set symptoms;
dummy=1;
run;
proc sort data=have;
by id;
proc transpose data=have out=want(drop= _Name_) ;
by id;
id symptoms;
var dummy;
run;

data want;
set want;
array num _numeric_;
do over num;
if missing(num) then num=0;
end;&lt;BR /&gt;run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 13 Sep 2018 19:59:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/LET-macro-statement/m-p/495481#M130770</guid>
      <dc:creator>SuryaKiran</dc:creator>
      <dc:date>2018-09-13T19:59:46Z</dc:date>
    </item>
    <item>
      <title>Re: %LET macro statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/LET-macro-statement/m-p/495482#M130771</link>
      <description>It worked!&lt;BR /&gt;It worked for the symptoms variable without dash in between but did not work for the variable like this "nickel_dime_les" , "Vaginal_lesion" do I need to add or delete something on the code you sent to me earlier?&lt;BR /&gt;</description>
      <pubDate>Thu, 13 Sep 2018 19:50:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/LET-macro-statement/m-p/495482#M130771</guid>
      <dc:creator>Dhana18</dc:creator>
      <dc:date>2018-09-13T19:50:31Z</dc:date>
    </item>
    <item>
      <title>Re: %LET macro statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/LET-macro-statement/m-p/495486#M130774</link>
      <description>&lt;P&gt;If you have spaces between the names that needs to be converted to variable names then use&amp;nbsp;&lt;STRONG&gt;options validvarname=v7; &lt;/STRONG&gt;before the transpose, this will convert the names to valid variable names (Replaces with "_" for all invalid characters for variable names.&lt;/P&gt;</description>
      <pubDate>Thu, 13 Sep 2018 20:04:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/LET-macro-statement/m-p/495486#M130774</guid>
      <dc:creator>SuryaKiran</dc:creator>
      <dc:date>2018-09-13T20:04:22Z</dc:date>
    </item>
    <item>
      <title>Re: %LET macro statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/LET-macro-statement/m-p/495487#M130775</link>
      <description>You may want to consider adding IDLABEL so the labels are the full name. You can also look at GLMOD to automatically create the dummy variables but it’s probably more work.</description>
      <pubDate>Thu, 13 Sep 2018 20:06:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/LET-macro-statement/m-p/495487#M130775</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-09-13T20:06:06Z</dc:date>
    </item>
    <item>
      <title>Re: %LET macro statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/LET-macro-statement/m-p/495491#M130778</link>
      <description>&lt;P&gt;Can you post a better and a true representative sample of your real&amp;nbsp; plz?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 13 Sep 2018 20:17:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/LET-macro-statement/m-p/495491#M130778</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-09-13T20:17:26Z</dc:date>
    </item>
    <item>
      <title>Re: %LET macro statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/LET-macro-statement/m-p/495510#M130783</link>
      <description>Hi I have a data like this;&lt;BR /&gt;data symptoms;&lt;BR /&gt;input id symptoms $ ;&lt;BR /&gt;cards;&lt;BR /&gt;1 discharge&lt;BR /&gt;2 pain&lt;BR /&gt;3 sore&lt;BR /&gt;4 odor warts&lt;BR /&gt;;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;I transposed the data set and it looks this now&lt;BR /&gt;&lt;BR /&gt;id vaginal_discharge pain_on_sex peniel_sore&lt;BR /&gt;1 peniel_sore&lt;BR /&gt;2 vaginal_discharge&lt;BR /&gt;3 pain_on_sex&lt;BR /&gt;4 pain_on_sex peniel_sore&lt;BR /&gt;&lt;BR /&gt;instead of this i would like to have like THIS (below)&lt;BR /&gt;id vaginal_discharge pain_on_sex peniel_sore&lt;BR /&gt;1 0 0 1&lt;BR /&gt;2 1 0 0&lt;BR /&gt;3 0 1 0&lt;BR /&gt;4 0 1 1&lt;BR /&gt;&lt;BR /&gt;The underscore between word of the variable is not working.&lt;BR /&gt;&lt;BR /&gt;I used if then statement like this;&lt;BR /&gt;if discharge ="discharge" then discharge="1";&lt;BR /&gt;&lt;BR /&gt;but i have hundreds of symptoms to write if then statement. is there a shorter way macro or something to do it efficiently?&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 13 Sep 2018 20:43:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/LET-macro-statement/m-p/495510#M130783</guid>
      <dc:creator>Dhana18</dc:creator>
      <dc:date>2018-09-13T20:43:31Z</dc:date>
    </item>
    <item>
      <title>Re: %LET macro statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/LET-macro-statement/m-p/495511#M130784</link>
      <description>&lt;P&gt;Fastest way might be use some code generation to generate an SQL statement to summarize by ID.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data symptoms;
  input id symptom $32. ;
cards;
1 discharge
2 pain
3 sore
4 odor
4 warts
;

proc sort data=symptoms(keep=symptom) nodupkey out=symptomlist ;
  by symptom;
run;

filename code temp;
data _null_;
  set symptomlist end=eof;
  file code ;
  if _n_=1 then put
 'proc sql noprint;'
/'create table want as select'
/' id'
  ;
  put ',max(symptom=' symptom :$quote. ') as ' symptom  ;
  if eof then put
 'from symptoms'
/'group by id'
/';'
/'quit;'
  ;
run;

%include code / source2;
proc print;
run;&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;Obs    id    discharge    odor    pain    sore    warts

 1      1        1          0       0       0       0
 2      2        0          0       1       0       0
 3      3        0          0       0       1       0
 4      4        0          1       0       0       1&lt;/PRE&gt;
&lt;PRE&gt;137 +proc sql noprint;
138 +create table want as select
139 + id
140 +,max(symptom="discharge" ) as discharge
141 +,max(symptom="odor" ) as odor
142 +,max(symptom="pain" ) as pain
143 +,max(symptom="sore" ) as sore
144 +,max(symptom="warts" ) as warts
145 +from symptoms
146 +group by id
147 +;
NOTE: SAS threaded sort was used.
NOTE: Table WORK.WANT created, with 4 rows and 6 columns.&lt;/PRE&gt;
&lt;P&gt;If your source data is NOT one observation per ID*SYMPTOM then you would need to change the logic of the test for whether a particular observation has an indication of that symptom.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also if your symptom values are not valid SAS variable names then you will have trouble.&amp;nbsp; You might need to generate unique names for the flag variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 13 Sep 2018 20:44:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/LET-macro-statement/m-p/495511#M130784</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-09-13T20:44:35Z</dc:date>
    </item>
    <item>
      <title>Re: %LET macro statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/LET-macro-statement/m-p/495665#M130861</link>
      <description>&lt;P&gt;It is called design matrix.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data symptoms;
input id symptoms $ ;
dummy=1;
cards;
1 discharge
2 pain
3 sore
4 odor warts
;
run;

proc logistic data=symptoms outdesign=want(drop=dummy) outdesignonly;
class symptoms/param=glm;
model dummy=id symptoms/noint;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 14 Sep 2018 13:17:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/LET-macro-statement/m-p/495665#M130861</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2018-09-14T13:17:58Z</dc:date>
    </item>
  </channel>
</rss>

