<?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 multiple columns based on a existing variable in a macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/create-multiple-columns-based-on-a-existing-variable-in-a-macro/m-p/671759#M201768</link>
    <description>&lt;P&gt;There are many places in this forum where experts advise against creating wide data sets with data in the column name, such as putting the zero value into YAS0, as these become difficult to analyze, and are not dynamic. Leaving the data in its original format not only makes the subsequent code easier to write, but avoids the problem that you state as "&lt;SPAN&gt;so that if the unique value changes to 2,3,4 or anything X Y Z it must create the columns similar way." And because we avoid this problem, a macro is normally not needed.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;So ... my advice is to restructure the problem so you don't need a wide data set with data in the variable name.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;If you explain more about what you plan to do with this data, we could definitely be more specific.&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 23 Jul 2020 11:04:11 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2020-07-23T11:04:11Z</dc:date>
    <item>
      <title>create multiple columns based on a existing variable in a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-multiple-columns-based-on-a-existing-variable-in-a-macro/m-p/671750#M201759</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In a dataset have a column named statatum which contains unique values 0 ,1 ,3 but in repetition.&lt;/P&gt;
&lt;P&gt;I would like to create multiple different columns in this dataset such as YAS YES YCS sep, but for all hte unique values. such as YAS0 YES0 YCS0 SEP0&amp;nbsp;YAS1 YES1 YCS1 SEP1&amp;nbsp;YAS3 YES3 YCS3 SEP3 .&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I require help to create these variables in form of a macro, so that if the unique value changes to 2,3,4 or anything X Y Z it must create the columns similar way.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 23 Jul 2020 10:47:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-multiple-columns-based-on-a-existing-variable-in-a-macro/m-p/671750#M201759</guid>
      <dc:creator>sahoositaram555</dc:creator>
      <dc:date>2020-07-23T10:47:41Z</dc:date>
    </item>
    <item>
      <title>Re: create multiple columns based on a existing variable in a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-multiple-columns-based-on-a-existing-variable-in-a-macro/m-p/671759#M201768</link>
      <description>&lt;P&gt;There are many places in this forum where experts advise against creating wide data sets with data in the column name, such as putting the zero value into YAS0, as these become difficult to analyze, and are not dynamic. Leaving the data in its original format not only makes the subsequent code easier to write, but avoids the problem that you state as "&lt;SPAN&gt;so that if the unique value changes to 2,3,4 or anything X Y Z it must create the columns similar way." And because we avoid this problem, a macro is normally not needed.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;So ... my advice is to restructure the problem so you don't need a wide data set with data in the variable name.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;If you explain more about what you plan to do with this data, we could definitely be more specific.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 23 Jul 2020 11:04:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-multiple-columns-based-on-a-existing-variable-in-a-macro/m-p/671759#M201768</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-07-23T11:04:11Z</dc:date>
    </item>
    <item>
      <title>Re: create multiple columns based on a existing variable in a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-multiple-columns-based-on-a-existing-variable-in-a-macro/m-p/671765#M201774</link>
      <description>Thanks &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;, sole intention of creating large dataset is to create use them as arguments in my proc template procedure. my intention is to create a survival plot where all these 3 types are 3 different strata. For each strata types, i need to use YAS &amp;amp;YCS in layout overlay as x &amp;amp; y, while others to be used in markercharacter options of proc template.&lt;BR /&gt;,&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 23 Jul 2020 11:12:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-multiple-columns-based-on-a-existing-variable-in-a-macro/m-p/671765#M201774</guid>
      <dc:creator>sahoositaram555</dc:creator>
      <dc:date>2020-07-23T11:12:54Z</dc:date>
    </item>
    <item>
      <title>Re: create multiple columns based on a existing variable in a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-multiple-columns-based-on-a-existing-variable-in-a-macro/m-p/671806#M201793</link>
      <description>&lt;P&gt;As far as I can see, survival plots are much more easily done on long data sets rather than wide data sets. So again, I urge you to not proceed with your plan as stated and reformulate the problem to use a long data set.&lt;/P&gt;</description>
      <pubDate>Thu, 23 Jul 2020 12:58:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-multiple-columns-based-on-a-existing-variable-in-a-macro/m-p/671806#M201793</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-07-23T12:58:15Z</dc:date>
    </item>
    <item>
      <title>Re: create multiple columns based on a existing variable in a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-multiple-columns-based-on-a-existing-variable-in-a-macro/m-p/671828#M201799</link>
      <description>I do agree! but he scenario is not only alone on survival plot, few modifications in the survival plot for which i have crated a template. if you please could look below to the code by which i'm trying to achieve the code and help me to automate,I would be grateful.&lt;BR /&gt;%macro hhh();&lt;BR /&gt;%do i =%scan() %to &amp;amp;n_categories;  **n_categories has all my unique values(0,1,3) sepated by space &lt;BR /&gt;proc transpose data= have;&lt;BR /&gt;id &amp;amp;&amp;amp;var&amp;amp;i.;&lt;BR /&gt;var statatum ;&lt;BR /&gt;run;&lt;BR /&gt;%end;&lt;BR /&gt;%mend;&lt;BR /&gt;%hhh();</description>
      <pubDate>Thu, 23 Jul 2020 14:07:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-multiple-columns-based-on-a-existing-variable-in-a-macro/m-p/671828#M201799</guid>
      <dc:creator>sahoositaram555</dc:creator>
      <dc:date>2020-07-23T14:07:58Z</dc:date>
    </item>
    <item>
      <title>Re: create multiple columns based on a existing variable in a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-multiple-columns-based-on-a-existing-variable-in-a-macro/m-p/671832#M201800</link>
      <description>&lt;P&gt;What do you actually have? What do you actually want?&lt;/P&gt;
&lt;P&gt;So the suffix 0,1,3 is coming from the variable STRATA.&lt;/P&gt;
&lt;P&gt;Where is the prefix YAS, YES, YCS coming from? Is that in another variable?&lt;BR /&gt;What value do you want the new variables to have? Is that in another variable?&lt;/P&gt;
&lt;P&gt;To just create the structure you could do something like this. First make a TALL dataset . Then TRANSPOSE it.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data tall;
  row=1;
  value=1;
  do prefix='YAS','YES','YCS','SEP';
    do suffix=0,1,3;
       output;
    end;
  end;
run;

proc transpose data=tall out=wide(drop=_name_);
  by row;
  id prefix suffix;
  var value;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="image.png" style="width: 768px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/47599i0E7FF0A39F3BA41C/image-size/large?v=v2&amp;amp;px=999" role="button" title="image.png" alt="image.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 23 Jul 2020 14:22:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-multiple-columns-based-on-a-existing-variable-in-a-macro/m-p/671832#M201800</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-07-23T14:22:29Z</dc:date>
    </item>
    <item>
      <title>Re: create multiple columns based on a existing variable in a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-multiple-columns-based-on-a-existing-variable-in-a-macro/m-p/671833#M201801</link>
      <description>Thanks &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;! to answer your all qustions: A) suffix 0,1,3 comes from the column statatum from HAVE dataset . B) YAS','YES','YCS','SEP' are my own defined column names that i would like to create. C)Values i need to define conditionally, many if else conditions based on these column names&lt;BR /&gt;The way you have created this is wonderful. Will save this. ONE ADVICE I NEED FURTHER ON THIS IS HOW TO AUTOMATE STEP IN YOUR CODE do suffix=0,1,3;&lt;BR /&gt;if this part is automated by passing 0 ,1 , 3 automated not by hard coding  then at could use it for my proc template.</description>
      <pubDate>Thu, 23 Jul 2020 14:33:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-multiple-columns-based-on-a-existing-variable-in-a-macro/m-p/671833#M201801</guid>
      <dc:creator>sahoositaram555</dc:creator>
      <dc:date>2020-07-23T14:33:34Z</dc:date>
    </item>
    <item>
      <title>Re: create multiple columns based on a existing variable in a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-multiple-columns-based-on-a-existing-variable-in-a-macro/m-p/671841#M201806</link>
      <description>&lt;P&gt;If you have a macro variable like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let strata = 0,1,3 ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then just use that in your DO statement.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;do suffix=&amp;amp;strata ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or make a dataset with one observation per value.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=have (keep=strata) out=suffix nodupkey;
  by strata;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And use the dataset instead of the DO loop.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data tall;
  set suffix ;
  do prefix='YAS',.....;
     ... calculate something here ... 
    output;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 23 Jul 2020 14:48:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-multiple-columns-based-on-a-existing-variable-in-a-macro/m-p/671841#M201806</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-07-23T14:48:32Z</dc:date>
    </item>
    <item>
      <title>Re: create multiple columns based on a existing variable in a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-multiple-columns-based-on-a-existing-variable-in-a-macro/m-p/671849#M201809</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/109034"&gt;@sahoositaram555&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;I do agree! but he scenario is not only alone on survival plot, few modifications in the survival plot for which i have crated a template. if you please could look below to the code by which i'm trying to achieve the code and help me to automate,I would be grateful.&lt;BR /&gt;%macro hhh();&lt;BR /&gt;%do i =%scan() %to &amp;amp;n_categories; **n_categories has all my unique values(0,1,3) sepated by space &lt;BR /&gt;proc transpose data= have;&lt;BR /&gt;id &amp;amp;&amp;amp;var&amp;amp;i.;&lt;BR /&gt;var statatum ;&lt;BR /&gt;run;&lt;BR /&gt;%end;&lt;BR /&gt;%mend;&lt;BR /&gt;%hhh();&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;From this, there is not enough information to know what you are doing or why you are doing this or where it is going. And so I will not comment on specific code at this time. I also point out that you continually arrive at a macro solution, and I simply am not in agreement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To determine the best structure of the data and a reasonable approach, the details must be provided about this survival plot and template, and I think we'd also need to see a portion of the data.&lt;/P&gt;</description>
      <pubDate>Thu, 23 Jul 2020 15:09:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-multiple-columns-based-on-a-existing-variable-in-a-macro/m-p/671849#M201809</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-07-23T15:09:36Z</dc:date>
    </item>
    <item>
      <title>Re: create multiple columns based on a existing variable in a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-multiple-columns-based-on-a-existing-variable-in-a-macro/m-p/671866#M201814</link>
      <description>Thanks &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;, i have took the distinct values by proc sql and stored them in a macro .Later with reference to your last post I've simply followed the proc transpose procedure to o the Job.&lt;BR /&gt;&lt;BR /&gt;Thanks again for looking patiently to the query and helping me building the concept!&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 23 Jul 2020 15:57:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-multiple-columns-based-on-a-existing-variable-in-a-macro/m-p/671866#M201814</guid>
      <dc:creator>sahoositaram555</dc:creator>
      <dc:date>2020-07-23T15:57:13Z</dc:date>
    </item>
  </channel>
</rss>

