<?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 can I substract characters from the value of selected macro variables using macro program? in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/How-can-I-substract-characters-from-the-value-of-selected-macro/m-p/556993#M9931</link>
    <description>&lt;P&gt;Thank you for your answer, Tom.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It seems to be complicated to use multiple '&amp;amp;' to resolve the macro variable. I couldn't find the rule using 5 '&amp;amp;'s to resolve the macro variable into '0outof1'. And if I use '&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;vname&amp;amp;i' in my code, it still does not work.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 08 May 2019 02:52:32 GMT</pubDate>
    <dc:creator>leehsin</dc:creator>
    <dc:date>2019-05-08T02:52:32Z</dc:date>
    <item>
      <title>How can I substract characters from the value of selected macro variables using macro program?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-can-I-substract-characters-from-the-value-of-selected-macro/m-p/556615#M9859</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am struggling with the macro codes to dynamically extract characters of the values from specific columns and put into newly created columns.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My actual data has tens of columns to be converted. Here I've made a sample data with 3 representative columns:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data oriData;
input ID aab $7. bbc $7.;
cards;
1 0outof1 0outof0
2 0outof0 0outof1
3 0outof0 0outof0
4 0outof1 0outof1
5 0outof0 0outof1
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;SPAN&gt;My goal is to convert the sample data into the one like the following data set:&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data finalData;
input ID BC_aab LC_aab BC_bbc LC_bbc;
cards;
1 0 1 0 0
2 0 0 0 1
3 0 0 0 0
4 0 1 0 1
5 0 0 0 1
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;SPAN&gt;Here are the codes I prepared to do this conversion:&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Collect column information */
proc sql;
create table vartable as
select * from sashelp.vcolumn
where libname='WORK' and memname="ORIDATA";
quit;

/* Make a list of column names to be converted */
data varlist;
set vartable;
where name not in ("ID");
keep name;
run;

/* Pass the column names into macro variables */
proc sql noprint;
select name
into :vname1 -
from work.varlist;
%let numobs=&amp;amp;sqlobs;
quit;

/* Examine the macro variables generated */
%put numobs= &amp;amp;sqlobs;
%put vname1= &amp;amp;vname1.;
%put vname2= &amp;amp;vname2.;
%put vname3= &amp;amp;vname3.;

/* Macro for the conversion */
%macro trfm(input,output);
data &amp;amp;output;
set &amp;amp;input;
%do i= 1 %to &amp;amp;numobs.;
BC_&amp;amp;&amp;amp;vname&amp;amp;i= %sysfunc(inputc(%substr(&amp;amp;&amp;amp;vname&amp;amp;i,1,1),8.));
LC_&amp;amp;&amp;amp;vname&amp;amp;i= %sysfunc(inputc(%substr(&amp;amp;&amp;amp;vname&amp;amp;i,%length(&amp;amp;&amp;amp;vname&amp;amp;i),1),8.));
drop &amp;amp;&amp;amp;vname&amp;amp;i.;
%end;
run;
%mend;

/* Testing */
%trfm(oriData,finalData);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;SPAN&gt;Here is the log after running the code:&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;1921  data oriData;
1922  input ID aab $7. bbc $7.;
1923  cards;


NOTE: The data set WORK.ORIDATA has 5 observations and 3 variables.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.00 seconds


1929  ;
1930  run;
1931
1932  proc sql;
1933     create table vartable as
1934        select * from sashelp.vcolumn
1935        where libname='WORK' and memname="ORIDATA";
NOTE: Table WORK.VARTABLE created, with 3 rows and 18 columns.

1936  quit;
NOTE: PROCEDURE SQL used (Total process time):
      real time           0.01 seconds
      cpu time            0.00 seconds

 

1937
1938  data varlist;
1939      set vartable;
1940      where name not in ("ID");
1941      keep name;
1942  run;


NOTE: There were 2 observations read from the data set WORK.VARTABLE.
      WHERE name not = 'ID';

NOTE: The data set WORK.VARLIST has 2 observations and 1 variables.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds


 

1943
1944  proc sql noprint;
1945      select name
1946      into :vname1 -
1947      from work.varlist;
1948  %let numobs=&amp;amp;sqlobs;
1949  quit;
NOTE: PROCEDURE SQL used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds
 

 

1950
1951  %put numobs= &amp;amp;sqlobs;
numobs= 2
1952  %put vname1= &amp;amp;vname1.;
vname1= aab
1953  %put vname2= &amp;amp;vname2.;
vname2= bbc
1954  %put vname3= &amp;amp;vname3.;
vname3= ccd
1955
1956  %macro trfm(input,output);
1957  data &amp;amp;output;
1958  set &amp;amp;input;
1959      %do i= 1 %to &amp;amp;numobs.;
1960          BC_&amp;amp;&amp;amp;vname&amp;amp;i= %sysfunc(inputc(%substr(&amp;amp;&amp;amp;vname&amp;amp;i,1,1),8.));
1961          LC_&amp;amp;&amp;amp;vname&amp;amp;i= %sysfunc(inputc(%substr(&amp;amp;&amp;amp;vname&amp;amp;i,%length(&amp;amp;&amp;amp;vname&amp;amp;i),1),8.));
1962          drop &amp;amp;&amp;amp;vname&amp;amp;i.;
1963      %end;
1964  run;
1965  %mend;

1966
1967  %trfm(oriData,finalData);
MPRINT(TRFM):   data finalData;
MPRINT(TRFM):   set oriData;
MPRINT(TRFM):   BC_aab= a ;
MPRINT(TRFM):   LC_aab= b ;
MPRINT(TRFM):   drop aab;
MPRINT(TRFM):   BC_bbc= b ;
MPRINT(TRFM):   LC_bbc= c ;
MPRINT(TRFM):   drop bbc;
MPRINT(TRFM):   run;


NOTE: Variable a is uninitialized.
NOTE: Variable b is uninitialized.
NOTE: Variable c is uninitialized.
NOTE: There were 5 observations read from the data set WORK.ORIDATA.
NOTE: The data set WORK.FINALDATA has 5 observations and 8 variables.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;SPAN&gt;The problem is that the program can't do extraction from the value of macro variables. Instead, it did extraction from the text of the macro variables. I couldn't find the solution, and ask for help from the community. Thanks in advance!!!&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 06 May 2019 23:42:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-can-I-substract-characters-from-the-value-of-selected-macro/m-p/556615#M9859</guid>
      <dc:creator>leehsin</dc:creator>
      <dc:date>2019-05-06T23:42:39Z</dc:date>
    </item>
    <item>
      <title>Re: How can I substract characters from the value of selected macro variables using macro program?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-can-I-substract-characters-from-the-value-of-selected-macro/m-p/556644#M9867</link>
      <description>&lt;P&gt;You may be picturing an overly complex process here.&amp;nbsp; Let's start by combining your first two steps:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table vartable as
select * from sashelp.vcolumn
where libname='WORK' and memname="ORIDATA"
and upcase(name) ne 'ID';
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;At this point, the program has all the information it needs to construct a DATA step holding the solution.&amp;nbsp; This is untested code, but should be in the ballpark:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
   set vartable end=done;
   if _n_=1 then call execute('data finalData; set oriData;');
   call execute ('length BC_' || name || 'LC_' || name || '$ 1;  drop ' || name || ';' ) ;
   call execute ('BC_' || name || '=' || name || ';' ) ;
   call execute ('LC_' || name || '= substr(' || name || ', length(' || name || ') ) ;' );
   if done then call execute('run;') ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can always turn it into a macro that uses parameters for the input and output data sets.&amp;nbsp; In that case, be sure to use double quotes instead of single quotes for the first CALL EXECUTE.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I defined the first and last characters as character variables with a length of 1.&amp;nbsp; That supports shortcuts, such as the equivalent of:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;length LC_aab $ 1;&lt;/P&gt;
&lt;P&gt;LC_aab = aab;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There's only room to store one character, so the value gets truncated automatically.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Give it a shot, see if it needs a tweak or not.&lt;/P&gt;</description>
      <pubDate>Tue, 07 May 2019 02:52:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-can-I-substract-characters-from-the-value-of-selected-macro/m-p/556644#M9867</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-05-07T02:52:17Z</dc:date>
    </item>
    <item>
      <title>Re: How can I substract characters from the value of selected macro variables using macro program?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-can-I-substract-characters-from-the-value-of-selected-macro/m-p/556772#M9885</link>
      <description>&lt;P&gt;Assuming there is only two columns split for aab bbc .&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data oriData;
input ID aab $ bbc $;
cards;
1 0outof1 0outof0
2 0outof0 0outof1
3 0outof0 0outof0
4 0outof1 0outof1
5 0outof0 0outof1
;
run;
data want;
 set oridata;
 BC_aab=scan(aab,1,,'kd');
 LC_aab=scan(aab,-1,,'kd');
 BC_bbc=scan(bbc,1,,'kd');
 LC_bbc=scan(bbc,-1,,'kd');
 drop aab bbc;
run;

proc print;run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 07 May 2019 13:45:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-can-I-substract-characters-from-the-value-of-selected-macro/m-p/556772#M9885</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2019-05-07T13:45:16Z</dc:date>
    </item>
    <item>
      <title>Re: How can I substract characters from the value of selected macro variables using macro program?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-can-I-substract-characters-from-the-value-of-selected-macro/m-p/556781#M9887</link>
      <description>&lt;P&gt;Fantastic! It's a very concise and efficient solution! I can easily use it to change it into a macro program. Combined with&amp;nbsp; a driver table which has the information for all macro variable, I can do the calculation on a big data. Thanks a lot!&lt;/P&gt;</description>
      <pubDate>Tue, 07 May 2019 14:17:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-can-I-substract-characters-from-the-value-of-selected-macro/m-p/556781#M9887</guid>
      <dc:creator>leehsin</dc:creator>
      <dc:date>2019-05-07T14:17:03Z</dc:date>
    </item>
    <item>
      <title>Re: How can I substract characters from the value of selected macro variables using macro program?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-can-I-substract-characters-from-the-value-of-selected-macro/m-p/556785#M9888</link>
      <description>&lt;P&gt;Thanks for your answer!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am working on a much more complicated data set than the sample data I presented for this question. It is a data driven coding issue. The point of my question I posted is actually about the two lines inside the macro %trfm:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;BC_&amp;amp;&amp;amp;vname&amp;amp;i= %sysfunc(inputc(%substr(&amp;amp;&amp;amp;vname&amp;amp;i,1,1),8.));&lt;BR /&gt;LC_&amp;amp;&amp;amp;vname&amp;amp;i= %sysfunc(inputc(%substr(&amp;amp;&amp;amp;vname&amp;amp;i,%length(&amp;amp;&amp;amp;vname&amp;amp;i),1),8.));&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;These two lines do not give the results I want. They substr the text of '&amp;amp;&amp;amp;vname&amp;amp;i' which is 'aab' or 'bbc' (the name of column), not the value of&amp;nbsp;'&amp;amp;&amp;amp;vname&amp;amp;i' which is '0outof1'...(the observations of the column). I was struggling at this point for those two lines above. Is there any way to modify the codes and make it work?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 07 May 2019 14:35:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-can-I-substract-characters-from-the-value-of-selected-macro/m-p/556785#M9888</guid>
      <dc:creator>leehsin</dc:creator>
      <dc:date>2019-05-07T14:35:04Z</dc:date>
    </item>
    <item>
      <title>Re: How can I substract characters from the value of selected macro variables using macro program?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-can-I-substract-characters-from-the-value-of-selected-macro/m-p/556795#M9889</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/215142"&gt;@leehsin&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thanks for your answer!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am working on a much more complicated data set than the sample data I presented for this question. It is a data driven coding issue. The point of my question I posted is actually about the two lines inside the macro %trfm:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;BC_&amp;amp;&amp;amp;vname&amp;amp;i= %sysfunc(inputc(%substr(&amp;amp;&amp;amp;vname&amp;amp;i,1,1),8.));&lt;BR /&gt;LC_&amp;amp;&amp;amp;vname&amp;amp;i= %sysfunc(inputc(%substr(&amp;amp;&amp;amp;vname&amp;amp;i,%length(&amp;amp;&amp;amp;vname&amp;amp;i),1),8.));&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;These two lines do not give the results I want. They substr the text of '&amp;amp;&amp;amp;vname&amp;amp;i' which is 'aab' or 'bbc' (the name of column), not the value of&amp;nbsp;'&amp;amp;&amp;amp;vname&amp;amp;i' which is '0outof1'...(the observations of the column). I was struggling at this point for those two lines above. Is there any way to modify the codes and make it work?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Which is why the proposed solutions did not involve trying to do this with macro code. Usually when I see code that is attempting to store a series of values into macro variables my immediate reaction is that those values should have been left in a dataset.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To get an answer to this specific question post some example values of the macro variables involved.&amp;nbsp; What is &amp;amp;I? What is VNAME1?&lt;/P&gt;
&lt;P&gt;It sounds like you think that VNAME1 has a value like AAB and there is a macro variable named AAB that has a value like 0outof1.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;188  %let i=1;
189  %let vname1=aab;
190  %let aab=0outof1;
191  %put '&amp;amp;vname1' = &amp;amp;vname1;
'&amp;amp;vname1' = aab
192  %put '&amp;amp;&amp;amp;vname&amp;amp;i' = &amp;amp;&amp;amp;vname&amp;amp;i ;
'&amp;amp;&amp;amp;vname&amp;amp;i' = aab
193  %put '&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;vname&amp;amp;i' = &amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;vname&amp;amp;i;
'&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;vname&amp;amp;i' = 0outof1&lt;/PRE&gt;
&lt;P&gt;So you need many more &amp;amp;'s to get that resolved. To see why use SYMBOLGEN option.&lt;/P&gt;
&lt;PRE&gt;194  options symbolgen;
195  %put '&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;vname&amp;amp;i' = &amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;vname&amp;amp;i;
SYMBOLGEN:  &amp;amp;&amp;amp; resolves to &amp;amp;.
SYMBOLGEN:  &amp;amp;&amp;amp; resolves to &amp;amp;.
SYMBOLGEN:  &amp;amp;&amp;amp; resolves to &amp;amp;.
SYMBOLGEN:  Macro variable I resolves to 1
SYMBOLGEN:  &amp;amp;&amp;amp; resolves to &amp;amp;.
SYMBOLGEN:  Macro variable VNAME1 resolves to aab
SYMBOLGEN:  Macro variable AAB resolves to 0outof1
'&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;vname&amp;amp;i' = 0outof1
196  options nosymbolgen;&lt;/PRE&gt;
&lt;P&gt;NOTE: don't leave SYMBOLGEN on if you are really running code like that or else your SAS log will have pages and pages of these messages.&lt;/P&gt;
&lt;P&gt;To avoid having to type so many &amp;amp;'s in your code just pull out the values into other macro variables.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let vname=&amp;amp;&amp;amp;vname&amp;amp;i;
%let value=&amp;amp;&amp;amp;&amp;amp;vname;
%put &amp;amp;=vname &amp;amp;=value ;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 07 May 2019 14:55:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-can-I-substract-characters-from-the-value-of-selected-macro/m-p/556795#M9889</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-05-07T14:55:22Z</dc:date>
    </item>
    <item>
      <title>Re: How can I substract characters from the value of selected macro variables using macro program?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-can-I-substract-characters-from-the-value-of-selected-macro/m-p/556993#M9931</link>
      <description>&lt;P&gt;Thank you for your answer, Tom.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It seems to be complicated to use multiple '&amp;amp;' to resolve the macro variable. I couldn't find the rule using 5 '&amp;amp;'s to resolve the macro variable into '0outof1'. And if I use '&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;vname&amp;amp;i' in my code, it still does not work.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 08 May 2019 02:52:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-can-I-substract-characters-from-the-value-of-selected-macro/m-p/556993#M9931</guid>
      <dc:creator>leehsin</dc:creator>
      <dc:date>2019-05-08T02:52:32Z</dc:date>
    </item>
    <item>
      <title>Re: How can I substract characters from the value of selected macro variables using macro program?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-can-I-substract-characters-from-the-value-of-selected-macro/m-p/557001#M9933</link>
      <description>&lt;P&gt;Why would you use 5 &amp;amp;?&lt;/P&gt;
&lt;PRE&gt;1    %let i=1;
2    %let vname1=abc;
3    %let abc=0outof1;
4    %put 1 &amp;amp;vname&amp;amp;i;
WARNING: Apparent symbolic reference VNAME not resolved.
1 &amp;amp;vname1
5    %put 2 &amp;amp;&amp;amp;vname&amp;amp;i;
2 abc
6    %put 3 &amp;amp;&amp;amp;&amp;amp;vname&amp;amp;i;
3 abc
7    %put 4 &amp;amp;&amp;amp;&amp;amp;&amp;amp;vname&amp;amp;i;
4 abc
8    %put 5 &amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;vname&amp;amp;i;
5 abc
9    %put 6 &amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;&amp;amp;vname&amp;amp;i;
6 0outof1&lt;/PRE&gt;</description>
      <pubDate>Wed, 08 May 2019 04:05:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-can-I-substract-characters-from-the-value-of-selected-macro/m-p/557001#M9933</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-05-08T04:05:06Z</dc:date>
    </item>
    <item>
      <title>Re: How can I substract characters from the value of selected macro variables using macro program?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-can-I-substract-characters-from-the-value-of-selected-macro/m-p/557004#M9935</link>
      <description>&lt;P&gt;There is no need for extensive macro code for this problem. Only useful place would be a macro variable that has the list of variables that you want to transform.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One of the best tools for generating variable names from data is PROC TRANSPOSE.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data oriData;
input ID aab :$7. bbc :$7.;
cards;
1 0outof1 0outof0
2 0outof0 0outof1
3 0outof0 0outof0
4 0outof1 0outof1
5 0outof0 0outof1
;

data tall ;
 set oridata;
 array x aab bbc ;
 length _name_ $32 type $2 value $1 ;

 do i=1 to dim(x);
   _name_ = vname(x[i]);
   type='BC';
   value=substr(x[i],1,1);
   output;
   type='LC';
   value=substr(x[i],length(x[i]));
   output;
 end;
run;
proc transpose data=tall out=want delim=_;
  by id;
  id type _name_;
  var value ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;PRE&gt;Obs    ID    _NAME_    BC_aab    LC_aab    BC_bbc    LC_bbc

 1      1    value       0         1         0         0
 2      2    value       0         0         0         1
 3      3    value       0         0         0         0
 4      4    value       0         1         0         1
 5      5    value       0         0         0         1&lt;/PRE&gt;</description>
      <pubDate>Wed, 08 May 2019 04:36:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-can-I-substract-characters-from-the-value-of-selected-macro/m-p/557004#M9935</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-05-08T04:36:48Z</dc:date>
    </item>
    <item>
      <title>Re: How can I substract characters from the value of selected macro variables using macro program?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-can-I-substract-characters-from-the-value-of-selected-macro/m-p/557105#M9948</link>
      <description>&lt;P&gt;Tom, this is a another excellent solution! It also automatically generates the new variable names using 'type'. Thank you so much! I appreciate it.&lt;/P&gt;</description>
      <pubDate>Wed, 08 May 2019 13:45:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-can-I-substract-characters-from-the-value-of-selected-macro/m-p/557105#M9948</guid>
      <dc:creator>leehsin</dc:creator>
      <dc:date>2019-05-08T13:45:20Z</dc:date>
    </item>
  </channel>
</rss>

