<?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: Dynamic code on basis of dataset variable values in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-code-on-basis-of-dataset-variable-values/m-p/525090#M142857</link>
    <description>I'd use the table to create a format and then use the new value with VVALUEX to obtain the correct date you want. If you know only one date will be filled there are other methods (COALESCE) that can be used instead.</description>
    <pubDate>Mon, 07 Jan 2019 16:10:07 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2019-01-07T16:10:07Z</dc:date>
    <item>
      <title>Dynamic code on basis of dataset variable values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-code-on-basis-of-dataset-variable-values/m-p/525005#M142819</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have some datasets in one library and i want to create new dataset based on values collected in dataset.This dataset is actually a specification sheet and it contain around 30 rows and 10 variables.For Example, i have created below dataset.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data create;
 input dataset $ 1-5 term $ 6-19 Variable $ 20-30;
 datalines;
 ABCD HYPERTENSION HYP_DTS
 ABCD FEVER        FEV_DTS
 BCDA CANCER       CAN_DTS
 DCBA ACIDITY             
;
 &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;My Requirement is to generate code as below&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data new;
 set abcd abcd bcda dcba;
  if term="Hypertension" then date=HYP_DTS;
  if term="FEVER" then date=FEV_DTS;
  if term="CANCER" then date=CAN_DTS;
 if term="ACIDITY" then date=" ";
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;While doing above operation, i also need to consider source dataset where this term is collected.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there any possibility of doing this kind programming ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Rajesh&lt;/P&gt;</description>
      <pubDate>Mon, 07 Jan 2019 11:57:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamic-code-on-basis-of-dataset-variable-values/m-p/525005#M142819</guid>
      <dc:creator>draroda</dc:creator>
      <dc:date>2019-01-07T11:57:21Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic code on basis of dataset variable values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-code-on-basis-of-dataset-variable-values/m-p/525012#M142823</link>
      <description>&lt;P&gt;Do you really want to duplicate the obs in [work.]abcd?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The code can be generated:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
   select dataset into :datasetList separated by ' '
      from create;
quit;

 data _null_;
   set work.create end=jobDone;
   file "generated_code.sas";

   length line $ 1000;

   if _n_ = 1 then do;
      put 'data new;';
      put "set &amp;amp;datasetList.;";
   end;


   line = catx(' ', 'if term =', quote(trim(Term)), 'then date =', Variable, ';');
   put line;

   if jobDone then do;
      put 'run;';
   end;
 run;

%include "generated_code.sas";&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 07 Jan 2019 12:14:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamic-code-on-basis-of-dataset-variable-values/m-p/525012#M142823</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2019-01-07T12:14:45Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic code on basis of dataset variable values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-code-on-basis-of-dataset-variable-values/m-p/525029#M142833</link>
      <description>&lt;P&gt;I would suggest making 2 %INCLUDEable files, which I often find a bit simpler syntax than SQL:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data create;
 input dataset $ 1-5 term $ 6-19 Variable $ 20-30;
 datalines;
 ABCD HYPERTENSION HYP_DTS
 ABCD FEVER        FEV_DTS
 BCDA CANCER       CAN_DTS
 DCBA ACIDITY             
;

filename dslist temp ;
filename  assigns temp;

data _null_;
  set create;
  file dslist ;
  put  dataset @;
  file assigns;
  if variable ^=' ' then put 'if term ='  term $quote20. 'then date=' variable ';';
run;

data want;
  set
  %include dslist /source2;;
  %include assigns / source2 ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Notes:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;The filenames dslist and assigns are placed in a "TEMP" space.&amp;nbsp; They will be deleted&amp;nbsp; by SAS at the end of the session.&lt;/LI&gt;
&lt;LI&gt;The trailing "@" in the PUT statement tells sas to refrain from entering an end-of-line character after writing the value of DATASET.&lt;/LI&gt;
&lt;LI&gt;In the "DATA WANT;" step there are 2 %include statements.
&lt;OL&gt;
&lt;LI&gt;The first one has two trailing semi-colons.&amp;nbsp; The first if&amp;nbsp; for the %include statement. The second is because the included text does not contain a semi-colon.&lt;/LI&gt;
&lt;LI&gt;The&amp;nbsp; second %include needs only one semicolon, because the included text has complete statements -- with&amp;nbsp; their own semi-colons.&lt;/LI&gt;
&lt;/OL&gt;
&lt;/LI&gt;
&lt;LI&gt;Also there is no IF statement for the TERM="ACIDITY" condition, because the date variable defaults to a missing value.&amp;nbsp; There's no need to assign a&amp;nbsp; blank (I assume all the DTS variables are character variables).&lt;/LI&gt;
&lt;/OL&gt;</description>
      <pubDate>Mon, 07 Jan 2019 14:21:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamic-code-on-basis-of-dataset-variable-values/m-p/525029#M142833</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2019-01-07T14:21:01Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic code on basis of dataset variable values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamic-code-on-basis-of-dataset-variable-values/m-p/525090#M142857</link>
      <description>I'd use the table to create a format and then use the new value with VVALUEX to obtain the correct date you want. If you know only one date will be filled there are other methods (COALESCE) that can be used instead.</description>
      <pubDate>Mon, 07 Jan 2019 16:10:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamic-code-on-basis-of-dataset-variable-values/m-p/525090#M142857</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-01-07T16:10:07Z</dc:date>
    </item>
  </channel>
</rss>

