<?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: macro write values into a variable instead of create new variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/macro-write-values-into-a-variable-instead-of-create-new/m-p/456624#M284346</link>
    <description>&lt;P&gt;Hi Tom,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So I did have my reason creating those dummies but thanks for mentioning the CLASS statement.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am&amp;nbsp;using the unique prefix method because my variable name list varied from model to model. What I did is create separate datasets to store the variable names and for each&amp;nbsp;logistic regression model, macro fetch the variable names from specific&amp;nbsp;namelist dataset.&amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a question about lrecl=75. Please correct me if I misunderstand.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In the example you provide, lrecl=75 means that the system can&amp;nbsp;write the external file with maximum 75 bytes. My problem goes to how do I know how much to specify ?&lt;/P&gt;&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;  &lt;SPAN class="token statement"&gt;file&lt;/SPAN&gt; &lt;SPAN class="token procnames"&gt;model&lt;/SPAN&gt; lrecl&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;75&lt;/SPAN&gt; &lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&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;Vi&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 23 Apr 2018 18:03:41 GMT</pubDate>
    <dc:creator>Vi_</dc:creator>
    <dc:date>2018-04-23T18:03:41Z</dc:date>
    <item>
      <title>macro write values into a variable instead of create new variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-write-values-into-a-variable-instead-of-create-new/m-p/456050#M284334</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Background:&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need a macro to create variable name list.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am using SAS Enterprise Guide 7.1&amp;nbsp; on Windows&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Issue:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have issues writing macro variables into a single field.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is an example:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data example ;
input Name $ 8.;
Datalines;
Jake Lin
Mike Lee
Jim Jo
Max Kim
;
run;&lt;/PRE&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;&lt;P&gt;Before create macro variable name list, I need to transform the space into underscore. My&amp;nbsp;macro as follow:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;%macro getNmList;
		%let namelist=%sysfunc(open(example));
		%let NObs=%sysfunc(attrn(&amp;amp;namelist,NOBS));
		%syscall set(namelist);

			Data TransformedName;

			set example;
			
			%do t=1 %to &amp;amp;NObs;
				%let rc=%sysfunc(fetchobs(&amp;amp;namelist,&amp;amp;t));
				%let Newname=%sysfunc(tranwrd(&amp;amp;name,%str( ),%str(_) ));
				%put &amp;amp;Newname;				

			TranName=&amp;amp;Newname;
			%end;
			run;


		%let namelist=sysfunc(close( namelist ));

%mend;
%getNmList&lt;/PRE&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;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The %put &amp;amp;Newname statement successfully returned my desired output values ( change space to underscore) :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Jake_Lin&lt;BR /&gt;Mike_Lee&lt;BR /&gt;Jim_Jo&lt;BR /&gt;Max_Kim&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;However, the output table is not what I expected.&lt;/STRONG&gt; The log and output result as follow:&lt;span class="lia-inline-image-display-wrapper lia-image-align-left" image-alt="sas log.PNG" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/20003i9A326F0DBC46C4AD/image-size/large?v=v2&amp;amp;px=999" role="button" title="sas log.PNG" alt="sas log.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-left" image-alt="sas results.PNG" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/20004iD204788E80097C0F/image-size/large?v=v2&amp;amp;px=999" role="button" title="sas results.PNG" alt="sas results.PNG" /&gt;&lt;/span&gt;&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;&lt;P&gt;&amp;nbsp;&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;&lt;P&gt;&amp;nbsp;&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;&lt;P&gt;&amp;nbsp;&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;&lt;P&gt;&amp;nbsp;&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;&lt;P&gt;&amp;nbsp;&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;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;(Node: I also notice the datatype for TranName is incorrect but I am not sure why)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like the result shown as :&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-left" image-alt="Wanted result.PNG" style="width: 325px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/20006i02B5D7C0D469D147/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Wanted result.PNG" alt="Wanted result.PNG" /&gt;&lt;/span&gt;&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;&lt;P&gt;&amp;nbsp;&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;&lt;P&gt;&amp;nbsp;&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;&lt;P&gt;&lt;STRONG&gt;Attempts:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;i). I suspect the error happened in this statement : TranName=&amp;amp;Newname; Thus, I tried using&amp;nbsp;&amp;nbsp;TranName=SYMGET('Newname');&lt;/P&gt;&lt;P&gt;But it only&amp;nbsp;returned the last value, and thus, the result TransName field are all Max_Kim.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ii). I also tried to re-write the macro using&amp;nbsp;call symputx as follows:&lt;/P&gt;&lt;PRE&gt;data _null_;

  set example ;

  call symputx(cats('origname',strip(_n_)),Name);

run;

%put &amp;amp;origname1 &amp;amp;origname2 &amp;amp;origname3 &amp;amp;origname4;

/****Log output : Jake Lin Mike Lee Jim Jo Max Kim**********/&lt;/PRE&gt;&lt;PRE&gt;%macro transpace;

data _null_;

%do i=1 %to 4;

%let tranName&amp;amp;i =tranwrd(('origname&amp;amp;i'),%str( ),%str(_));

%end;

run;
%mend;

%transpace

%put &amp;amp;tranName1;

/*******Log CANNT get &amp;amp;tranName1 and I having 

WARNING: Apparent symbolic reference TRANNAME1 not resolved.*********/&lt;/PRE&gt;&lt;P&gt;After all the attempts, I am not sure how can I get to my desire name list~~~please help~~~~&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you in advance.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Vi&lt;/P&gt;</description>
      <pubDate>Fri, 20 Apr 2018 19:23:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-write-values-into-a-variable-instead-of-create-new/m-p/456050#M284334</guid>
      <dc:creator>Vi_</dc:creator>
      <dc:date>2018-04-20T19:23:20Z</dc:date>
    </item>
    <item>
      <title>Re: macro write values into a variable instead of create new variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-write-values-into-a-variable-instead-of-create-new/m-p/456051#M284335</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;tranname="&amp;amp;newname";&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But you don't need macros here, this can be done entirely in a DATA step using the TRANSLATE function.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 20 Apr 2018 19:26:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-write-values-into-a-variable-instead-of-create-new/m-p/456051#M284335</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2018-04-20T19:26:45Z</dc:date>
    </item>
    <item>
      <title>Re: macro write values into a variable instead of create new variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-write-values-into-a-variable-instead-of-create-new/m-p/456066#M284336</link>
      <description>&lt;P&gt;Ok...here's another way, using SQL. I assume you wanted a quoted delimited list, but if you don't remove the QUOTE() function and you can modify the separated by section.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
name='Jack Johnson'; output;
name = 'Green Goblin'; output;
name = 'Bruce Wayne'; output;
run;

proc sql noprint;
select quote(translate(strip(name), "_", " ")) into : name_list separated by ", "
from have;
quit;

%put &amp;amp;name_list;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you want multiple macro variables:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
proc sql noprint;
select quote(translate(strip(name), "_", " ")) into : name1- 
from have;
quit;



%put &amp;amp;name1.;
%put &amp;amp;name2.;
%put &amp;amp;name3.;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 20 Apr 2018 20:17:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-write-values-into-a-variable-instead-of-create-new/m-p/456066#M284336</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-04-20T20:17:43Z</dc:date>
    </item>
    <item>
      <title>Re: macro write values into a variable instead of create new variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-write-values-into-a-variable-instead-of-create-new/m-p/456072#M284337</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;SPAN&gt;Paige,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thank you for fast response. However, changing the code to tranname="&amp;amp;newname"&amp;nbsp;&lt;/SPAN&gt;does not solve my problem because the output table is not what I want. It only returned the last value:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-left" image-alt="01result.PNG" style="width: 320px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/20009iA569DC051BFAB358/image-size/large?v=v2&amp;amp;px=999" role="button" title="01result.PNG" alt="01result.PNG" /&gt;&lt;/span&gt;&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;&lt;P&gt;&amp;nbsp;&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;&lt;P&gt;&amp;nbsp;&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;&lt;P&gt;i understand that I can possibly change this in a DATA step. But in my case, if I do it in DATA step, I might need to change my code more than having this macro to run.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Vi&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>Fri, 20 Apr 2018 20:22:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-write-values-into-a-variable-instead-of-create-new/m-p/456072#M284337</guid>
      <dc:creator>Vi_</dc:creator>
      <dc:date>2018-04-20T20:22:40Z</dc:date>
    </item>
    <item>
      <title>Re: macro write values into a variable instead of create new variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-write-values-into-a-variable-instead-of-create-new/m-p/456076#M284338</link>
      <description>&lt;P&gt;You just want the varaible in the data set that way?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then use a query with a computed column that is:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token function"&gt;translate&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;strip&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;name&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt; &lt;SPAN class="token string"&gt;"_"&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt; &lt;SPAN class="token string"&gt;" "&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;or:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 20 Apr 2018 20:27:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-write-values-into-a-variable-instead-of-create-new/m-p/456076#M284338</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-04-20T20:27:49Z</dc:date>
    </item>
    <item>
      <title>Re: macro write values into a variable instead of create new variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-write-values-into-a-variable-instead-of-create-new/m-p/456083#M284339</link>
      <description>&lt;P&gt;If your final goal is to put all the values into a macro then try using Proc SQL with INTO:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data example ;
input Name $ 8.;
Datalines;
Jake Lin
Mike Lee
Jim Jo
Max Kim
;
run;

PROC SQl;
select Name INTO: Names1 separated by ','
from example
;
quit;
proc sql;
select translate(strip(name), "_", " ") into: Names2 separated by " "
from example;
quit;
%put &amp;amp;Names1;
%put &amp;amp;names2;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 20 Apr 2018 20:33:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-write-values-into-a-variable-instead-of-create-new/m-p/456083#M284339</guid>
      <dc:creator>SuryaKiran</dc:creator>
      <dc:date>2018-04-20T20:33:27Z</dc:date>
    </item>
    <item>
      <title>Re: macro write values into a variable instead of create new variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-write-values-into-a-variable-instead-of-create-new/m-p/456101#M284340</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/205885"&gt;@Vi_&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Hi&amp;nbsp;&lt;SPAN&gt;Paige,&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Thank you for fast response. However, changing the code to tranname="&amp;amp;newname"&amp;nbsp;&lt;/SPAN&gt;does not solve my problem because the output table is not what I want. It only returned the last value:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-left" image-alt="01result.PNG" style="width: 320px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/20009iA569DC051BFAB358/image-size/large?v=v2&amp;amp;px=999" role="button" title="01result.PNG" alt="01result.PNG" /&gt;&lt;/span&gt;&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;
&lt;P&gt;&amp;nbsp;&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;
&lt;P&gt;&amp;nbsp;&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;
&lt;P&gt;i understand that I can possibly change this in a DATA step. But in my case, if I do it in DATA step, I might need to change my code more than having this macro to run.&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Maybe because &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;did not provide complete code you did not understand his recommendation.&lt;/P&gt;
&lt;P&gt;Please see&lt;/P&gt;
&lt;PRE&gt;data transformedname;
   set example;
   tranname = translate(strip(name),'_',' ');
run;&lt;/PRE&gt;
&lt;P&gt;for a non-macro approach to generate what I think is the desired output.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The potential for issues with macro variable scope and repeated requirements to iterate through the value list based on the value of a variable in your data set sounds like the start of a nightmare.&lt;/P&gt;</description>
      <pubDate>Fri, 20 Apr 2018 21:52:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-write-values-into-a-variable-instead-of-create-new/m-p/456101#M284340</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-04-20T21:52:39Z</dc:date>
    </item>
    <item>
      <title>Re: macro write values into a variable instead of create new variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-write-values-into-a-variable-instead-of-create-new/m-p/456110#M284341</link>
      <description>&lt;P&gt;To get better help you need to explain more clearly what you want.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;I need a macro to create variable name list.&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Do you want the list in a macro variable?&amp;nbsp; So perhaps something like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let namelist=Jake_Lin Mike_Lee Jim_Jo Max_Kim ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If so there is no need to create a macro to do that, a simple SQL query will do.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
select translate(strip(name),'_',' '))
  into :namelist separated by ' '
  from example
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The macro code you posted seems to be confused about what happens in macro code and what happens in SAS code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you really wanted to create the list in a dataset variable then use a data step for that.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data TransformedName;
  length TranName $400 ;
  retain tranname;
  set example end=eof ;
  tranname=catx(' ',tranname,translate(strip(name),'_',' '));
  if eof;
  keep tranname;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 20 Apr 2018 22:45:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-write-values-into-a-variable-instead-of-create-new/m-p/456110#M284341</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-04-20T22:45:42Z</dc:date>
    </item>
    <item>
      <title>Re: macro write values into a variable instead of create new variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-write-values-into-a-variable-instead-of-create-new/m-p/456155#M284342</link>
      <description>&lt;P&gt;You have the typical misunderstanding of the macro processor.&lt;/P&gt;
&lt;P&gt;The macro processor is a CODE GENERATOR, not a tool for data manipulation. It works BEFORE(!!!) any base SAS code starts to execute.&lt;/P&gt;
&lt;P&gt;So the macro creates this data step code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data TransformedName;
set example;
TranName=Jake_Lin;
TranName=Mike_Lee;
TranName=Jim_Jo;
TranName=Max_Kim;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You see you have no strings to the right, but something SAS sees as variable names, and the data step compiler dutifully creates them&amp;nbsp;(as they are not on your input dataset), using the default type numeric, and they stay uninitialized (see the NOTEs). Since the right side of your assignment is numeric, tranname is also created numeric.&lt;/P&gt;
&lt;P&gt;Even if those variables were present, only the last assignment would take effect before the observation is written out.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What you want is extremely easily accomplished with a simple call of the translate() function, no macro needed AT ALL. See Maxim 11.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Attempt i) failed because the data step only sees the last value assigned to &amp;amp;newname.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Use&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;'s code and carefully study the second sentence of my post.&lt;/P&gt;</description>
      <pubDate>Sat, 21 Apr 2018 09:30:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-write-values-into-a-variable-instead-of-create-new/m-p/456155#M284342</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-04-21T09:30:19Z</dc:date>
    </item>
    <item>
      <title>Re: macro write values into a variable instead of create new variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-write-values-into-a-variable-instead-of-create-new/m-p/456179#M284343</link>
      <description>&lt;P&gt;Reeza:&lt;/P&gt;&lt;P&gt;&lt;SPAN class="login-bold"&gt;Thanks for sharing two ways to help me approach&amp;nbsp;my goal. Both of them work for me!!&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="login-bold"&gt;Ballardw:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="login-bold"&gt;Thank you for providing the full code and point out some potential issues&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="login-bold"&gt;Suryakiran:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="login-bold"&gt;You code is very easy to understand. Thanks!!&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="login-bold"&gt;KurtBremser:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="login-bold"&gt;Thank you for answer the other issue I have and pointing out my misunderstand&amp;nbsp;or unclear part of sas&amp;nbsp;macro. I somehow assuming&amp;nbsp;sas&amp;nbsp;macro is the same as other programming languages that can easily write a for loop to iterate my data. But it seems like macro is a bit different than what I thought it is.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Tom:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="login-bold"&gt;In short, I&amp;nbsp;wrote a maco to automatically create dummy&amp;nbsp;variables (using proc transpose) and I used Proc&amp;nbsp;sql&amp;nbsp;namelist&amp;nbsp;to get the dummy&amp;nbsp;variable names and put it into Proc Logistic Model statement. However, It did not work because all the dummy variable name were cut off when proc sql namelist&amp;nbsp;macro meets space. Eventually, the macro&amp;nbsp;namelist&amp;nbsp;returns partial variable name, thus, my logistic model cannot&amp;nbsp;read it correctly.&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="login-bold"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;I think in the end the solution to my problem is to change the variable name before creating dummies. I appreciate all the responses.&amp;nbsp;&lt;SPAN class="login-bold"&gt;Thank you all for giving me a macro class.&amp;nbsp;I learned a lot from this post!!&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="login-bold"&gt;Vi&lt;/SPAN&gt;&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;&lt;P&gt;&amp;nbsp;&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, 21 Apr 2018 14:16:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-write-values-into-a-variable-instead-of-create-new/m-p/456179#M284343</guid>
      <dc:creator>Vi_</dc:creator>
      <dc:date>2018-04-21T14:16:29Z</dc:date>
    </item>
    <item>
      <title>Re: macro write values into a variable instead of create new variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-write-values-into-a-variable-instead-of-create-new/m-p/456180#M284344</link>
      <description>&lt;P&gt;Since Reeza provides the solution to my desired output the first, I will select his post as the solution to this post.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 21 Apr 2018 14:21:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-write-values-into-a-variable-instead-of-create-new/m-p/456180#M284344</guid>
      <dc:creator>Vi_</dc:creator>
      <dc:date>2018-04-21T14:21:15Z</dc:date>
    </item>
    <item>
      <title>Re: macro write values into a variable instead of create new variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-write-values-into-a-variable-instead-of-create-new/m-p/456181#M284345</link>
      <description>&lt;P&gt;Not sure why you are making your own dummy variables. PROC LOGISTIC does support the CLASS statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you just want to make a list of variables in SAS code then just use a variable list.&amp;nbsp; If you name the variable using numeric suffixes then you can use&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;model x=dummy1-dummy2000;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you name them all with a unique prefix you can use&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;model x=dummy: ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you know their order in the data set you can use a positional list&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;model x=first_dummy -- last_dummy ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Also macro code is not the only way to generate SAS code.&amp;nbsp;If you have a list of variable names in a SAS dataset and you want to use it to generate SAS statements then use a data step to make a file that contains the statement(s) and use %INCLUDE to place it where you need it in your program.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename model temp;
data _null_;
  set varlist end=eof;
  file model lrecl=75 ;
  if _n_=1 then put 'MODEL x=';
  put varname @;
  if eof then put / ';' ;
run;

proc logistic .... ;
%include model;
...&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 21 Apr 2018 15:12:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-write-values-into-a-variable-instead-of-create-new/m-p/456181#M284345</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-04-21T15:12:23Z</dc:date>
    </item>
    <item>
      <title>Re: macro write values into a variable instead of create new variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-write-values-into-a-variable-instead-of-create-new/m-p/456624#M284346</link>
      <description>&lt;P&gt;Hi Tom,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So I did have my reason creating those dummies but thanks for mentioning the CLASS statement.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am&amp;nbsp;using the unique prefix method because my variable name list varied from model to model. What I did is create separate datasets to store the variable names and for each&amp;nbsp;logistic regression model, macro fetch the variable names from specific&amp;nbsp;namelist dataset.&amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a question about lrecl=75. Please correct me if I misunderstand.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In the example you provide, lrecl=75 means that the system can&amp;nbsp;write the external file with maximum 75 bytes. My problem goes to how do I know how much to specify ?&lt;/P&gt;&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;  &lt;SPAN class="token statement"&gt;file&lt;/SPAN&gt; &lt;SPAN class="token procnames"&gt;model&lt;/SPAN&gt; lrecl&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;75&lt;/SPAN&gt; &lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&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;Vi&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 23 Apr 2018 18:03:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-write-values-into-a-variable-instead-of-create-new/m-p/456624#M284346</guid>
      <dc:creator>Vi_</dc:creator>
      <dc:date>2018-04-23T18:03:41Z</dc:date>
    </item>
    <item>
      <title>Re: macro write values into a variable instead of create new variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-write-values-into-a-variable-instead-of-create-new/m-p/456633#M284347</link>
      <description>&lt;P&gt;The maximum length of a variable name in SAS is 32 characters.&lt;/P&gt;
&lt;P&gt;SAS doesn’t really care what line length you use for the Include file.&lt;/P&gt;
&lt;P&gt;But the maximum line length that a human can reasonably read/scan is about 75 characters. That is why I added the LRECL=75 option.&amp;nbsp;&amp;nbsp; Code with lines longer than that is a real pain in the *** to read and edit.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 23 Apr 2018 18:30:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-write-values-into-a-variable-instead-of-create-new/m-p/456633#M284347</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-04-23T18:30:12Z</dc:date>
    </item>
    <item>
      <title>Re: macro write values into a variable instead of create new variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-write-values-into-a-variable-instead-of-create-new/m-p/456776#M284348</link>
      <description>&lt;P&gt;Also see Maxim 12.&lt;/P&gt;</description>
      <pubDate>Tue, 24 Apr 2018 06:37:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-write-values-into-a-variable-instead-of-create-new/m-p/456776#M284348</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-04-24T06:37:02Z</dc:date>
    </item>
  </channel>
</rss>

