<?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: SAS variable like instruction in sas in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SAS-variable-like-instruction-in-sas/m-p/378437#M90927</link>
    <description>&lt;P&gt;with the help of the Astounding's solution I will use this sas code, that resolve the problem:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data _null_;
set T1;
file 'my.translations.sas' noprint;
a=cats('var',_N_,'num');
b=cats('var',_N_,'num2');
put a ' = ' num ';' ;
put b ' = ' num2 ';' ;
run;&lt;/PRE&gt;
&lt;P&gt;&lt;BR /&gt;Thanks to everyone for help me to find the solution!! &amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 22 Jul 2017 16:16:13 GMT</pubDate>
    <dc:creator>Rakeon</dc:creator>
    <dc:date>2017-07-22T16:16:13Z</dc:date>
    <item>
      <title>SAS variable like instruction in sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-variable-like-instruction-in-sas/m-p/378383#M90895</link>
      <description>&lt;P&gt;Hi,&lt;BR /&gt;I have a table(import from excel- - 800 row) like this:&lt;/P&gt;
&lt;PRE&gt;data t1;&lt;BR /&gt;input index $ num $ num2 $;&lt;BR /&gt;datalines;&lt;BR /&gt;var1 a+b b&lt;BR /&gt;var2 b b+c&lt;BR /&gt;run;&lt;/PRE&gt;
&lt;P&gt;and the table tab1 is this:&lt;/P&gt;
&lt;P&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/10472iAE6F73AE9F771A63/image-size/original?v=1.0&amp;amp;px=-1" border="0" alt="Immagine.png" title="Immagine.png" /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now I have another table:&lt;/P&gt;
&lt;PRE&gt;data t2;
 input a b c;
datalines;
1 2 3
4 5 6
run;&lt;/PRE&gt;
&lt;P&gt;like this:&lt;/P&gt;
&lt;P&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/10473iD4789FF4E3CA669F/image-size/original?v=1.0&amp;amp;px=-1" border="0" alt="Immagine.png" title="Immagine.png" /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;- In table t2, I would like calculate the sum of the variable that are described in the table t1:&lt;/P&gt;
&lt;P&gt;and the result shoul be like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/10478iF01038730B40A2D1/image-size/original?v=1.0&amp;amp;px=-1" border="0" alt="Immagine.png" title="Immagine.png" /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;I have mainly this two problem:&lt;/P&gt;
&lt;P&gt;1)&lt;STRONG&gt; transpose the tab 1&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;2)&lt;STRONG&gt;how to execute the value of variable like instruction(code) of SAS&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;some of you has any idea?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 22 Jul 2017 15:30:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-variable-like-instruction-in-sas/m-p/378383#M90895</guid>
      <dc:creator>Rakeon</dc:creator>
      <dc:date>2017-07-22T15:30:33Z</dc:date>
    </item>
    <item>
      <title>Re: SAS variable like instruction in sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-variable-like-instruction-in-sas/m-p/378390#M90897</link>
      <description>&lt;P&gt;I was thinking about call execute as below, but it is not resolving the num wih a+b values. Any thoughts from experts would be appreciated&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data t1;
input index $ num $ num2 $;
datalines;
var1 a+b b
var2 b b+c
run;


data t2;
 input a b c;
datalines;
1 2 3
4 5 6
run;

proc transpose data=t1 out=test;
id index;
var num num2;
run;

data want;
merge t1(in=x) t2(in=y);

run;

data want2;
set want;
call execute('sum='||num||';');
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 22 Jul 2017 07:55:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-variable-like-instruction-in-sas/m-p/378390#M90897</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2017-07-22T07:55:39Z</dc:date>
    </item>
    <item>
      <title>Re: SAS variable like instruction in sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-variable-like-instruction-in-sas/m-p/378396#M90899</link>
      <description>&lt;P&gt;We'll need a slightly longer version of your data. &amp;nbsp;It's not clear from what you posted whether it's really a requirement to transpose the first table.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One approach would be to write the instructions to a file, based on T1. &amp;nbsp;For example (skipping the transpose), use T1 to write out:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if _n_=1 then do;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;sum_var1 = a+b;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;sum_var2 = b;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;else if _n_=2 then do;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;sum_var1 = b;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;sum_var2 = b+c;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then get the final result using:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;set t2;&lt;/P&gt;
&lt;P&gt;%include 'my.file';&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Sat, 22 Jul 2017 10:04:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-variable-like-instruction-in-sas/m-p/378396#M90899</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-07-22T10:04:05Z</dc:date>
    </item>
    <item>
      <title>Re: SAS variable like instruction in sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-variable-like-instruction-in-sas/m-p/378404#M90902</link>
      <description>&lt;P&gt;Ok,&lt;/P&gt;
&lt;P&gt;Thanks for your answers,&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;&amp;nbsp;my t1 table has 800 row(I can't put the file excel..it's private data..).. and my goal was to do everything authomatically.&lt;/P&gt;
&lt;P&gt;Yes,.. I thought to make it with the transpose, and after, execute the value of the variable (a,a+b, sum(a,b).....) &amp;nbsp;as SAS code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I just would like to know, if there is a way to execute the value of variable as SAS base code.&lt;BR /&gt;&lt;BR /&gt;yes, if there is another solution, I accept all...&lt;BR /&gt;&lt;BR /&gt;thanks&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 22 Jul 2017 10:59:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-variable-like-instruction-in-sas/m-p/378404#M90902</guid>
      <dc:creator>Rakeon</dc:creator>
      <dc:date>2017-07-22T10:59:55Z</dc:date>
    </item>
    <item>
      <title>Re: SAS variable like instruction in sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-variable-like-instruction-in-sas/m-p/378410#M90906</link>
      <description>&lt;P&gt;I still can't tell whether a transpose is needed or not. &amp;nbsp;At a minimum, I would need to see a third row in T1. &amp;nbsp;So omitting the transpose, here is more of the detail.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data _null_;&lt;/P&gt;
&lt;P&gt;set T1;&lt;/P&gt;
&lt;P&gt;file 'my.translations.sas' noprint;&lt;/P&gt;
&lt;P&gt;if _n_ &amp;gt; 1 then put 'else';&lt;/P&gt;
&lt;P&gt;put 'if _n_ = ' _n_ 'then do;' ;&lt;/P&gt;
&lt;P&gt;put 'sum_var1 = ' num ';' ;&lt;/P&gt;
&lt;P&gt;put 'sum_var2 = ' num2 ';' ;&lt;/P&gt;
&lt;P&gt;put 'end;' ;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;At this point, take a look at the file my.translations.sas to verify that it contains the right code. &amp;nbsp;Then:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;set t2;&lt;/P&gt;
&lt;P&gt;%include 'my.translations.sas';&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The idea is that the first DATA step uses the first table to write out the code that is needed, and save it in a file. &amp;nbsp;The second DATA step brings in that code, applying it to the second data set.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The piece I'm not sure about is still whether the first data set can be used as is, vs. needs to be transposed.&lt;/P&gt;</description>
      <pubDate>Sat, 22 Jul 2017 13:21:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-variable-like-instruction-in-sas/m-p/378410#M90906</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-07-22T13:21:37Z</dc:date>
    </item>
    <item>
      <title>Re: SAS variable like instruction in sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-variable-like-instruction-in-sas/m-p/378418#M90913</link>
      <description>&lt;P&gt;Your metadata table is confusing. You have a row with variable name of VAR1 but then you have TWO columns with formulas. &amp;nbsp;Do you want to generate two ROWS so that VAR1 can have those two different values? &amp;nbsp;Or do you want to make two variables&amp;nbsp;and just use 'VAR1' as the prefix for the variable name? &amp;nbsp;If so what names do you want for the two variables?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;From the result you posted it looks like you have picked option C which is use the formulas on the diagonals. So VAR1 uses the first formula VAR2 uses the second formula, ...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 22 Jul 2017 14:28:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-variable-like-instruction-in-sas/m-p/378418#M90913</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-07-22T14:28:51Z</dc:date>
    </item>
    <item>
      <title>Re: SAS variable like instruction in sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-variable-like-instruction-in-sas/m-p/378419#M90914</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data t1;
input index $ num $ num2 $;
datalines;
var1 a+b b
var2 b b+c
;
run;

data t2;
 input a b c;
datalines;
1 2 3
4 5 6
;
run;

data want;
 merge t2 t1;
 length temp want1 want2 $ 80;
 array x{*} a b c;

 temp=num;
 do i=1 to dim(x);
   temp=compress(tranwrd(lowcase(temp),lowcase(vname(x{i})),x{i}),' ');
 end;
 if notdigit(strip(temp))=0 then want1=temp;
    else want1=resolve(cats('%sysevalf(',strip(temp),')'));


 temp=num2;
 do i=1 to dim(x);
   temp=compress(tranwrd(lowcase(temp),lowcase(vname(x{i})),x{i}),' ');
 end;
 if notdigit(strip(temp))=0 then want2=temp;
    else want2=resolve(cats('%sysevalf(',strip(temp),')'));


 drop i temp;
 run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 22 Jul 2017 14:29:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-variable-like-instruction-in-sas/m-p/378419#M90914</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2017-07-22T14:29:08Z</dc:date>
    </item>
    <item>
      <title>Re: SAS variable like instruction in sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-variable-like-instruction-in-sas/m-p/378432#M90924</link>
      <description>&lt;DIV class="lia-message-heading lia-component-message-header"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV id="messagebodydisplay_0_5" class="lia-message-body lia-component-body"&gt;
&lt;DIV class="lia-message-body-content"&gt;
&lt;P&gt;Sorry,&lt;BR /&gt;I want to apologize...I made the mistake in the original post...and now I have modified It(the result of original post).&lt;BR /&gt;&lt;BR /&gt;what I want, &amp;nbsp;is to generate for every row of the table t2:&lt;/P&gt;
&lt;P&gt;var1_of_num&lt;/P&gt;
&lt;P&gt;var1_of_num2&lt;/P&gt;
&lt;P&gt;var2_of_num&lt;/P&gt;
&lt;P&gt;var2_of_num2&lt;BR /&gt;&lt;BR /&gt;Sorry again, for my mistake...&amp;nbsp;&lt;/P&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;</description>
      <pubDate>Sat, 22 Jul 2017 15:52:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-variable-like-instruction-in-sas/m-p/378432#M90924</guid>
      <dc:creator>Rakeon</dc:creator>
      <dc:date>2017-07-22T15:52:45Z</dc:date>
    </item>
    <item>
      <title>Re: SAS variable like instruction in sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-variable-like-instruction-in-sas/m-p/378437#M90927</link>
      <description>&lt;P&gt;with the help of the Astounding's solution I will use this sas code, that resolve the problem:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data _null_;
set T1;
file 'my.translations.sas' noprint;
a=cats('var',_N_,'num');
b=cats('var',_N_,'num2');
put a ' = ' num ';' ;
put b ' = ' num2 ';' ;
run;&lt;/PRE&gt;
&lt;P&gt;&lt;BR /&gt;Thanks to everyone for help me to find the solution!! &amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 22 Jul 2017 16:16:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-variable-like-instruction-in-sas/m-p/378437#M90927</guid>
      <dc:creator>Rakeon</dc:creator>
      <dc:date>2017-07-22T16:16:13Z</dc:date>
    </item>
  </channel>
</rss>

