<?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 variable name from concatenation of a character string and a numeric array value in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Creating-variable-name-from-concatenation-of-a-character-string/m-p/666865#M199600</link>
    <description>&lt;P&gt;Great solution, and quick as well! Thanks!&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;I actually solved it myself before seeing your answer using a 'call execute - datastep-macro' instead, but i think i like your solution better. It must be quicker than to read and write to the same data-set many times &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 03 Jul 2020 17:22:37 GMT</pubDate>
    <dc:creator>Malthe</dc:creator>
    <dc:date>2020-07-03T17:22:37Z</dc:date>
    <item>
      <title>Creating variable name from concatenation of a character string and a numeric array value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-variable-name-from-concatenation-of-a-character-string/m-p/666613#M199479</link>
      <description>&lt;P&gt;Hi there and in advance thanks a lot for your help! I'm using SAS Enterprise Guide 7.15.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a dataset with patients, baseline-dates and scoring-dates. For each patient i have the same baseline-date and multiple scoring-dates (&amp;gt;20). I want to see whether the scoring-dates are within certain periods of time from the baseline-date: 1 year, 2 years, 3 years ... - 100 years;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Instead of writing multiple lines of codes, i am trying to boil it down to a more manageable size.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is a data-example with five scoring dates:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data one;
length patient_id $ 8;
format baseline_date score_date date9.;
input patient_id baseline_date score_date;
cards;
Patient1 0 200
Patient1 0 400
Patient1 0 600
Patient1 0 800
Patient1 0 1000
;

run;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is my code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data scoring_within_year_x;
set one;
array a_withinyear [5] (1 2 3 5 10 100); 

/* For simplicity boiled down to smaller fixed array, these are the values i need the most */&amp;nbsp;

do i = 1 to dim(a_withinyear);
if intnx('year',baseline_date,a_withinyear[i],'same' &amp;gt;= score_date then&amp;nbsp;

/* Here i have my first problem, i want to name the new variable as a concatenation of a string and the value of the array - something like this */

cats('Score_within_',a_withinyear[i],'_year') = 1&lt;BR /&gt;&lt;BR /&gt;/* Here i have my second problem. I want to output multiple variables to the same observation as shown underneath */ 
end;
run;&amp;nbsp;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So ideally my output for the 4th line of the original data would look like this:&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Patient_id | Baseline_date | Score_date | Score_within_1_year | Score_within_2_year | Score_within_5_year | etc...&lt;/P&gt;&lt;P&gt;Patient1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;800&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;1&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; 1&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; 0&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I hope you can help me &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 02 Jul 2020 15:09:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-variable-name-from-concatenation-of-a-character-string/m-p/666613#M199479</guid>
      <dc:creator>Malthe</dc:creator>
      <dc:date>2020-07-02T15:09:13Z</dc:date>
    </item>
    <item>
      <title>Re: Creating variable name from concatenation of a character string and a numeric array value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-variable-name-from-concatenation-of-a-character-string/m-p/666621#M199483</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;try Proc Transpose:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data one;
length patient_id $ 8;
format baseline_date score_date date9.;
input patient_id baseline_date score_date;
cards;
Patient1 0 200
Patient1 0 400
Patient1 0 600
Patient1 0 800
Patient1 0 1000
;
run;

data tmp;
set one;
array a_withinyear [6] _temporary_ (1 2 3 5 10 100) ; 

/* For simplicity boiled down to smaller fixed array, these are the values i need the most */ 

do i = 1 to dim(a_withinyear);
  if intnx('year',baseline_date,a_withinyear[i],'same') &amp;gt;= score_date then 
    do;
      varname = cats('Score_within_',a_withinyear[i],'_year');
      flag = 1;
      output;
    end;

end;
run; 
proc sort data=tmp;
  by patient_id baseline_date score_date varname;
run; 

proc transpose data = tmp out = scoring_within_year_x(drop = _name_);
  by patient_id baseline_date score_date;
  var flag;
  id varname;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Thu, 02 Jul 2020 15:17:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-variable-name-from-concatenation-of-a-character-string/m-p/666621#M199483</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2020-07-02T15:17:35Z</dc:date>
    </item>
    <item>
      <title>Re: Creating variable name from concatenation of a character string and a numeric array value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-variable-name-from-concatenation-of-a-character-string/m-p/666865#M199600</link>
      <description>&lt;P&gt;Great solution, and quick as well! Thanks!&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;I actually solved it myself before seeing your answer using a 'call execute - datastep-macro' instead, but i think i like your solution better. It must be quicker than to read and write to the same data-set many times &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 03 Jul 2020 17:22:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-variable-name-from-concatenation-of-a-character-string/m-p/666865#M199600</guid>
      <dc:creator>Malthe</dc:creator>
      <dc:date>2020-07-03T17:22:37Z</dc:date>
    </item>
  </channel>
</rss>

