<?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: create a macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/create-a-macro/m-p/678764#M204923</link>
    <description>&lt;P&gt;Sorry, I need to create a macro variable &amp;amp;x. and its should resolve like this&lt;/P&gt;&lt;P&gt;input var1 $10 var2 $9 var3 $11&lt;/P&gt;&lt;P&gt;I just gave some random values for those variables. All I need is to create a macro variable and it should resolve like mentioned above. Sorry for the confusion.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 23 Aug 2020 19:12:18 GMT</pubDate>
    <dc:creator>helpmedoubts</dc:creator>
    <dc:date>2020-08-23T19:12:18Z</dc:date>
    <item>
      <title>create a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-a-macro/m-p/678762#M204921</link>
      <description>&lt;P&gt;data one;&lt;BR /&gt;input variable$1-8;&lt;BR /&gt;datalines;&lt;BR /&gt;var1 $10&lt;BR /&gt;var2 $9&lt;BR /&gt;var3 $11&lt;BR /&gt;;&lt;BR /&gt;run;&lt;BR /&gt;Now i need to create a macro &amp;amp;x.using the above dataset&lt;BR /&gt;data two;&lt;BR /&gt;input &amp;amp;x;&lt;BR /&gt;datalines;&lt;BR /&gt;a b c&lt;BR /&gt;;&lt;BR /&gt;run;&lt;BR /&gt;macro &amp;amp;x should resolve like this - var1 $10 var2 $9 var3 $11&lt;BR /&gt;I couldn't get the slightest idea how to do this. Can someone help with this?&lt;/P&gt;</description>
      <pubDate>Sun, 23 Aug 2020 18:53:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-a-macro/m-p/678762#M204921</guid>
      <dc:creator>helpmedoubts</dc:creator>
      <dc:date>2020-08-23T18:53:19Z</dc:date>
    </item>
    <item>
      <title>Re: create a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-a-macro/m-p/678763#M204922</link>
      <description>&lt;P&gt;First of all, this really isn't clear. You mention you want a "macro", but it seems like you really want a "macro variable". "Macro" and "macro variable" are not the same thing. Please confirm you really want a "macro variable".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Next, even if you get a macro variable named &amp;amp;X that has the value you want, it will not produce a meaningful result in DATA TWO if you run it. You need to make sure that the macro variable, when replaced by its actual value, produces legal valid working SAS code (and this isn't working properly).&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;If I am understanding you properly, in DATA TWO, you want the second line to say (after replacing &amp;amp;X with its value)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;input var1 $10 var2 $9 var3 $11;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;but this will not work. It will read the data incorrectly. These are the things that you have to think about and fix before you try to create a macro variable and use it. What should this INPUT statement say? If you had to write it without macro variables, show me an INPUT statement that will actually work here and produce the desired result. To me, creating code that works properly without macro variables is a MANDATORY (not optional) first step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What is the desired result from DATA TWO anyway? You don't tell us.&lt;/P&gt;</description>
      <pubDate>Sun, 23 Aug 2020 19:14:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-a-macro/m-p/678763#M204922</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-08-23T19:14:00Z</dc:date>
    </item>
    <item>
      <title>Re: create a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-a-macro/m-p/678764#M204923</link>
      <description>&lt;P&gt;Sorry, I need to create a macro variable &amp;amp;x. and its should resolve like this&lt;/P&gt;&lt;P&gt;input var1 $10 var2 $9 var3 $11&lt;/P&gt;&lt;P&gt;I just gave some random values for those variables. All I need is to create a macro variable and it should resolve like mentioned above. Sorry for the confusion.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 23 Aug 2020 19:12:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-a-macro/m-p/678764#M204923</guid>
      <dc:creator>helpmedoubts</dc:creator>
      <dc:date>2020-08-23T19:12:18Z</dc:date>
    </item>
    <item>
      <title>Re: create a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-a-macro/m-p/678765#M204924</link>
      <description>&lt;P&gt;But as I said, this INPUT statement will read the data incorrectly.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What should the INPUT statement say (without macro variables, using only SAS data step code) so that it will read the data correctly?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I really want you to understand the thought process here. Your macro variable, when it is replaced by its value, must produce working SAS code. You need to have that working SAS code before you can create a macro variable. You can't just create any text string in your macro variable &amp;amp;X and expect it to do what you want.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you don't have working SAS code to start with in DATA TWO, then using a macro variable will fail as well.&lt;/P&gt;</description>
      <pubDate>Sun, 23 Aug 2020 19:18:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-a-macro/m-p/678765#M204924</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-08-23T19:18:53Z</dc:date>
    </item>
    <item>
      <title>Re: create a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-a-macro/m-p/678770#M204925</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/339838"&gt;@helpmedoubts&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;data one;&lt;BR /&gt;input variable$1-8;&lt;BR /&gt;datalines;&lt;BR /&gt;var1 $10&lt;BR /&gt;var2 $9&lt;BR /&gt;var3 $11&lt;BR /&gt;;&lt;BR /&gt;run;&lt;BR /&gt;Now i need to create a macro &amp;amp;x.using the above dataset&lt;BR /&gt;data two;&lt;BR /&gt;input &amp;amp;x;&lt;BR /&gt;datalines;&lt;BR /&gt;a b c&lt;BR /&gt;;&lt;BR /&gt;run;&lt;BR /&gt;macro &amp;amp;x should resolve like this - var1 $10 var2 $9 var3 $11&lt;BR /&gt;I couldn't get the slightest idea how to do this. Can someone help with this?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;This is not possible; the data in dataset one can't be used to create working code. You need to fix dataset one first, before you can use it to create the macro variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 23 Aug 2020 20:02:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-a-macro/m-p/678770#M204925</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-08-23T20:02:40Z</dc:date>
    </item>
    <item>
      <title>Re: create a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-a-macro/m-p/678773#M204927</link>
      <description>&lt;P&gt;Sorry, Now I understood your point.&lt;/P&gt;&lt;P&gt;I need dataset two like this based on dataset one&lt;/P&gt;&lt;P&gt;data one;&lt;BR /&gt;input variable$1-8;&lt;BR /&gt;datalines;&lt;BR /&gt;var1 $10&lt;BR /&gt;var2 $9&lt;BR /&gt;var3 $11&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;crreate a macro variable &amp;amp;x.&lt;/P&gt;&lt;P&gt;length &amp;amp;x.; should resolve length var1 $10 var2 $9 var3 $11;&lt;/P&gt;&lt;P&gt;data two;&lt;BR /&gt;length var1 $10 var2 $9 var3 $11;&lt;BR /&gt;input var1 $ var2 $ var3 $;&lt;BR /&gt;datalines;&lt;BR /&gt;a b c&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;Hope I am clear this time.&lt;/P&gt;</description>
      <pubDate>Sun, 23 Aug 2020 20:09:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-a-macro/m-p/678773#M204927</guid>
      <dc:creator>helpmedoubts</dc:creator>
      <dc:date>2020-08-23T20:09:13Z</dc:date>
    </item>
    <item>
      <title>Re: create a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-a-macro/m-p/678778#M204928</link>
      <description>&lt;P&gt;Data Two was defined as (taken from the original post):&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data two;
input &amp;amp;x;
datalines;
a b c
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then suppose the macro variable is assigned by %LET, as in:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let x = var1 $10 var2 $9 var3 $11 ;
data two;
input &amp;amp;x;
datalines;
a b c
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;then it will resolve to:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data two;
input var1 $10 var2 $9 var3 $11;
datalines;
a b c
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and it will run without errors.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If I understand correctly, the target is to create the macro variable X in data One,&lt;/P&gt;
&lt;P&gt;then the code to do it is:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data one;
  infile datalines eov=eof;
  length x $30; retain x;
  input variables $1-8;
  x = catx(' ',x,variables); 
  call symputx('x',x);
datalines4;
var1 $10
var2 $9
var3 $11
;;;;
run;
%put x= &amp;amp;x;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 23 Aug 2020 20:28:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-a-macro/m-p/678778#M204928</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2020-08-23T20:28:16Z</dc:date>
    </item>
    <item>
      <title>Re: create a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-a-macro/m-p/678782#M204929</link>
      <description>&lt;P&gt;Your original post stated that you want to create an INPUT statement using the macro variable &amp;amp;X.&amp;nbsp; As others have mentioned, that gives you a program that does the wrong thing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, you later clarified that saying that you want the macro variable to be used in a LENGTH statement.&amp;nbsp; That is quite possible.&amp;nbsp; After creating the data set ONE, you would use:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
select variable into : x separated by ' ' from one;
quit;

%put &amp;amp;X;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now you have the macro variable X with the desired value, and you can experiment with using it any way that you see fit.&lt;/P&gt;</description>
      <pubDate>Sun, 23 Aug 2020 21:27:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-a-macro/m-p/678782#M204929</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2020-08-23T21:27:32Z</dc:date>
    </item>
    <item>
      <title>Re: create a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-a-macro/m-p/678785#M204930</link>
      <description>&lt;P&gt;If you want to use metadata (ONE) to generate code then make sure the metadata has the information you need.&lt;/P&gt;
&lt;P&gt;Your example seems to have mashed two variables into into one. The name of the variable and the length of the variable.&amp;nbsp; I say length instead of format because the values you list do not have the period needed to be format specifications, but are valid syntax for setting the length of a variable in a LENGTH statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You also need to know what code you want to generate.&amp;nbsp; Your proposed code does not look right.&amp;nbsp; Do you really want VAR1 to be the single character in column 10 of the input line? And VAR2 to the single character in column 9?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So assuming your values are lengths you could modify your code like this to do something reasonable.&amp;nbsp; (It is still not clear if it is what you want to do.)&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data one;
  varnum+1;
  input variable :$32.  length :$6.;
datalines;
var1 $10
var2 $9
var3 $11
;

proc sql noprint;
  select catx(' ',variable,length) 
     into :lengths separated by ' '
     from one
     order by varnum
  ;
quit;

data two;
   length &amp;amp;lengths;
   input (_all_) (+0);
datalines;
a b c
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 23 Aug 2020 23:08:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-a-macro/m-p/678785#M204930</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-08-23T23:08:31Z</dc:date>
    </item>
    <item>
      <title>Re: create a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-a-macro/m-p/678803#M204938</link>
      <description>&lt;P&gt;Thank you so much. It worked.&lt;/P&gt;</description>
      <pubDate>Mon, 24 Aug 2020 03:10:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-a-macro/m-p/678803#M204938</guid>
      <dc:creator>helpmedoubts</dc:creator>
      <dc:date>2020-08-24T03:10:31Z</dc:date>
    </item>
    <item>
      <title>Re: create a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-a-macro/m-p/678804#M204939</link>
      <description>&lt;P&gt;Thank you. This code worked. The values I gave in the original dataset were single characters. I just gave them as an example. My main doubt was how to create a macro variable. Thanks a lot for the code. it worked perfectly. But I couldn't understand this line&lt;/P&gt;&lt;PRE class="language-sas"&gt;&lt;CODE&gt;input (_all_) (+0);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;Could you please explain this?&lt;/P&gt;&lt;P&gt;I never saw _all_ in input statement. It's very interesting. Learning something new everyday from this community.&lt;/P&gt;</description>
      <pubDate>Mon, 24 Aug 2020 03:18:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-a-macro/m-p/678804#M204939</guid>
      <dc:creator>helpmedoubts</dc:creator>
      <dc:date>2020-08-24T03:18:12Z</dc:date>
    </item>
    <item>
      <title>Re: create a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-a-macro/m-p/678808#M204942</link>
      <description>&lt;P&gt;_ALL_ is a variable list.&amp;nbsp; Just like A B C or VAR1-VAR2 or _NUMERIC_ or _CHARACTER_.&lt;/P&gt;
&lt;P&gt;The parentheses are used when specifying a list of variables followed by a list of informats in a INPUT (or formats in a PUT) statement.&lt;/P&gt;
&lt;P&gt;The +0 is a cursor movement command that will move the&amp;nbsp; cursor by zero character positions.&amp;nbsp; You just need it so the list of informats is not empty.&lt;/P&gt;</description>
      <pubDate>Mon, 24 Aug 2020 04:49:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-a-macro/m-p/678808#M204942</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-08-24T04:49:34Z</dc:date>
    </item>
    <item>
      <title>Re: create a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-a-macro/m-p/715818#M221129</link>
      <description>&lt;P&gt;Thank You!&lt;/P&gt;</description>
      <pubDate>Mon, 01 Feb 2021 16:35:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-a-macro/m-p/715818#M221129</guid>
      <dc:creator>helpmedoubts</dc:creator>
      <dc:date>2021-02-01T16:35:39Z</dc:date>
    </item>
  </channel>
</rss>

