<?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 Problem in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Macro-Problem/m-p/586154#M167297</link>
    <description>&lt;P&gt;Take your code:&lt;/P&gt;
&lt;PRE&gt;data Apple_price(drop=Age);
length key $25 Apple_price_c $10 Factor_c $10;
set in.Apple_price;
key = compress('Case'||ID||'_'||Group||'_'||put(Unit,z2.),,'kadp');
Apple_price_c = 'Apple_price';
Factor_c = 'Factor';
run;&lt;/PRE&gt;
&lt;P&gt;Use the CHANGE command to convert APPLE to &amp;amp;COV.&amp;nbsp; &amp;nbsp;If you are using the SAS editor just type this on the command line:&lt;/P&gt;
&lt;PRE&gt;change 'Apple' '&amp;amp;cov.' i all&lt;/PRE&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data &amp;amp;cov._price(drop=Age);
length key $25 &amp;amp;cov._price_c $10 Factor_c $10;
set in.&amp;amp;cov._price;
key = compress('Case'||ID||'_'||Group||'_'||put(Unit,z2.),,'kadp');
&amp;amp;cov._price_c = '&amp;amp;cov._price';
Factor_c = 'Factor';
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then make sure that your macro variable reference is not inside of string quoted used single quotes instead of double quotes.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data &amp;amp;cov._price(drop=Age);
length key $25 &amp;amp;cov._price_c $10 Factor_c $10;
set in.&amp;amp;cov._price;
key = compress('Case'||ID||'_'||Group||'_'||put(Unit,z2.),,'kadp');
&amp;amp;cov._price_c = "&amp;amp;cov._price";
Factor_c = 'Factor';
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 04 Sep 2019 15:00:30 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2019-09-04T15:00:30Z</dc:date>
    <item>
      <title>Macro Problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Problem/m-p/586142#M167292</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I get a code and want to turn it into macro.&lt;/P&gt;&lt;PRE&gt;data Apple_price(drop=Age);&lt;BR /&gt;length key $25 Apple_price_c $10 Factor_c $10;&lt;BR /&gt;set in.Apple_price;&lt;BR /&gt;key = compress('Case'||ID||'_'||Group||'_'||put(Unit,z2.),,'kadp');&lt;BR /&gt;Apple_price_c = 'Apple_price';&lt;BR /&gt;Factor_c = 'Factor';&lt;BR /&gt;run;&lt;/PRE&gt;&lt;P&gt;Since I've pear and peach data as well. But my code seems wrong. Could anybody can give some suggestions?&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro fruit(covlist);
	%if &amp;amp;covlist. ^= none %then %do;
        %let y = 1;
        %let cov = %scan(&amp;amp;covlist., &amp;amp;y., ' ');
		%do %until(&amp;amp;cov. eq %nrstr( ));

			data &amp;amp;cov._price(drop=Age);
				length key $25 &amp;amp;cov._price_c $10 Factor_c $10;
 			    set in.Apple_price;
				key = %compress('Case'||ID||'_'||Group||'_'||%put(Unit,z2.),,'kadp');
				&amp;amp;cov._price_c = %compress("&amp;amp;cov."||'_price',,'kadp');
				Factor_c = 'Factor';
			run;

		%let y = %eval(&amp;amp;y. + 1);
        %let cov = %scan(&amp;amp;covlist., &amp;amp;y., ' ');
        %end;
    %end;

%mend fruit;

%fruit(covlist = apple pear peach)&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Many Thanks!&lt;/P&gt;</description>
      <pubDate>Wed, 04 Sep 2019 14:40:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Problem/m-p/586142#M167292</guid>
      <dc:creator>jordenlam</dc:creator>
      <dc:date>2019-09-04T14:40:51Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Problem/m-p/586144#M167293</link>
      <description>&lt;P&gt;Why are you calling the %COMPRESS() macro?&amp;nbsp; Do you have a definition for that macro?&lt;/P&gt;
&lt;PRE&gt;678   %put %compress();
WARNING: Apparent invocation of macro COMPRESS not resolved.
&lt;/PRE&gt;
&lt;P&gt;Why did you insert a %PUT statement into the middle of one of the lines of SAS code you are trying to get the macro to create?&lt;/P&gt;
&lt;PRE&gt;680   %put(Unit,z2.),,'kadp');
(Unit,z2.),,'kadp')&lt;/PRE&gt;
&lt;P&gt;Only change the parts of the program that are actually changing.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 04 Sep 2019 14:49:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Problem/m-p/586144#M167293</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-09-04T14:49:22Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Problem/m-p/586145#M167294</link>
      <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;But my code seems wrong.&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Explain further. What is wrong? We don't know what you mean.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Also, run this line of code first&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options mprint;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;and then execute your macro again, and then show us the LOG. Click on the {i} icon and paste your code as text into the window that appears. &lt;STRONG&gt;Do not skip this step.&amp;nbsp;&lt;/STRONG&gt;This is an important step to maintain the formatting of the LOG and make it much more readable.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 04 Sep 2019 14:55:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Problem/m-p/586145#M167294</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-09-04T14:55:25Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Problem/m-p/586148#M167296</link>
      <description>&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token keyword"&gt;set&lt;/SPAN&gt; &lt;SPAN class="token operator"&gt;in&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;Apple_price&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Your hard coded your input data set?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I suspect you need to be using your macro variable there as well.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/280929"&gt;@jordenlam&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I get a code and want to turn it into macro.&lt;/P&gt;
&lt;PRE&gt;data Apple_price(drop=Age);&lt;BR /&gt;length key $25 Apple_price_c $10 Factor_c $10;&lt;BR /&gt;set in.Apple_price;&lt;BR /&gt;key = compress('Case'||ID||'_'||Group||'_'||put(Unit,z2.),,'kadp');&lt;BR /&gt;Apple_price_c = 'Apple_price';&lt;BR /&gt;Factor_c = 'Factor';&lt;BR /&gt;run;&lt;/PRE&gt;
&lt;P&gt;Since I've pear and peach data as well. But my code seems wrong. Could anybody can give some suggestions?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro fruit(covlist);
	%if &amp;amp;covlist. ^= none %then %do;
        %let y = 1;
        %let cov = %scan(&amp;amp;covlist., &amp;amp;y., ' ');
		%do %until(&amp;amp;cov. eq %nrstr( ));

			data &amp;amp;cov._price(drop=Age);
				length key $25 &amp;amp;cov._price_c $10 Factor_c $10;
 			    set in.Apple_price;
				key = %compress('Case'||ID||'_'||Group||'_'||%put(Unit,z2.),,'kadp');
				&amp;amp;cov._price_c = %compress("&amp;amp;cov."||'_price',,'kadp');
				Factor_c = 'Factor';
			run;

		%let y = %eval(&amp;amp;y. + 1);
        %let cov = %scan(&amp;amp;covlist., &amp;amp;y., ' ');
        %end;
    %end;

%mend fruit;

%fruit(covlist = apple pear peach)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Many Thanks!&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 04 Sep 2019 14:54:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Problem/m-p/586148#M167296</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-09-04T14:54:04Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Problem/m-p/586154#M167297</link>
      <description>&lt;P&gt;Take your code:&lt;/P&gt;
&lt;PRE&gt;data Apple_price(drop=Age);
length key $25 Apple_price_c $10 Factor_c $10;
set in.Apple_price;
key = compress('Case'||ID||'_'||Group||'_'||put(Unit,z2.),,'kadp');
Apple_price_c = 'Apple_price';
Factor_c = 'Factor';
run;&lt;/PRE&gt;
&lt;P&gt;Use the CHANGE command to convert APPLE to &amp;amp;COV.&amp;nbsp; &amp;nbsp;If you are using the SAS editor just type this on the command line:&lt;/P&gt;
&lt;PRE&gt;change 'Apple' '&amp;amp;cov.' i all&lt;/PRE&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data &amp;amp;cov._price(drop=Age);
length key $25 &amp;amp;cov._price_c $10 Factor_c $10;
set in.&amp;amp;cov._price;
key = compress('Case'||ID||'_'||Group||'_'||put(Unit,z2.),,'kadp');
&amp;amp;cov._price_c = '&amp;amp;cov._price';
Factor_c = 'Factor';
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then make sure that your macro variable reference is not inside of string quoted used single quotes instead of double quotes.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data &amp;amp;cov._price(drop=Age);
length key $25 &amp;amp;cov._price_c $10 Factor_c $10;
set in.&amp;amp;cov._price;
key = compress('Case'||ID||'_'||Group||'_'||put(Unit,z2.),,'kadp');
&amp;amp;cov._price_c = "&amp;amp;cov._price";
Factor_c = 'Factor';
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 04 Sep 2019 15:00:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Problem/m-p/586154#M167297</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-09-04T15:00:30Z</dc:date>
    </item>
  </channel>
</rss>

