<?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: Using CALL SYMPUT in same datastep in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Using-CALL-SYMPUT-in-same-datastep/m-p/69219#M15009</link>
    <description>John,&lt;BR /&gt;
Though the problems in the upper and lower code snippets are different, they are all based on the same timing issue - the maco processor processes at a different time than the data step.  For example, let's start with a little demo code:&lt;BR /&gt;
%let SCOPE=GLOBAL;&lt;BR /&gt;
TITLE "&amp;amp;SCOPE macro variables before DATA _NULL_";&lt;BR /&gt;
proc print data=sashelp.vmacro;&lt;BR /&gt;
   where SCOPE="&amp;amp;SCOPE";&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
This produces a report:&lt;BR /&gt;
&lt;BR /&gt;
OUTPUT window:&lt;BR /&gt;
GLOBAL macro variables before DATA _NULL_ &lt;BR /&gt;
&lt;BR /&gt;
Obs   scope       name       offset  value &lt;BR /&gt;
1       GLOBAL   SCOPE   0        GLOBAL&lt;BR /&gt;
&lt;BR /&gt;
Note that the macro variable yr does not yet exist.  Now for your code:&lt;BR /&gt;
&lt;BR /&gt;
data _null_;&lt;BR /&gt;
   call symput('yr', year(today() ) );&lt;BR /&gt;
   put "&amp;amp;yr.";&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
When submitted the first time, the macro variable yr still does not exist so cannot be resolved before the DATA step is compiled.  See the SAS log:&lt;BR /&gt;
WARNING: Apparent symbolic reference YR not resolved.&lt;BR /&gt;
10   run;&lt;BR /&gt;
&amp;amp;yr.&lt;BR /&gt;
&lt;BR /&gt;
Because the macro processor could not resolve the variable yr, the DATA step compiles with the value '&amp;amp;yr.' in the PUT statement.&lt;BR /&gt;
&lt;BR /&gt;
Now, when the data step executed for the first time, it created and populated the macro variable yr.  Run this code after the first DATA _NULL_ step to prove that this is true:&lt;BR /&gt;
&lt;BR /&gt;
TITLE "&amp;amp;SCOPE macro variables after DATA _NULL_";&lt;BR /&gt;
proc print data=sashelp.vmacro;&lt;BR /&gt;
   where SCOPE="&amp;amp;SCOPE";&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
OUTPUT window:&lt;BR /&gt;
Global macro variables before DATA _NULL_ &lt;BR /&gt;
&lt;BR /&gt;
Obs  scope       name       offset   value &lt;BR /&gt;
1      GLOBAL   SCOPE    0        GLOBAL &lt;BR /&gt;
2      GLOBAL   YR           0        2011 &lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
So the second time you run your DATA step, the variable yr already exists, and it will be resolved before the DATA step gets compiled.  This will avoid the WARNING and replace the text &amp;amp;yr. in the PUT statement with 2011 as the data step compiles.  This is why the second time you run the code, you get the expected results. &lt;BR /&gt;
&lt;BR /&gt;
Hope this helps.&lt;BR /&gt;
May the SAS be with you &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;</description>
    <pubDate>Wed, 25 May 2011 14:18:01 GMT</pubDate>
    <dc:creator>SASJedi</dc:creator>
    <dc:date>2011-05-25T14:18:01Z</dc:date>
    <item>
      <title>Using CALL SYMPUT in same datastep</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-CALL-SYMPUT-in-same-datastep/m-p/69217#M15007</link>
      <description>[pre]&lt;BR /&gt;
data _null_;&lt;BR /&gt;
   call symput('yr', year(today() ) );&lt;BR /&gt;
&lt;BR /&gt;
   put "&amp;amp;yr.";&lt;BR /&gt;
run;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
95   data _null_;&lt;BR /&gt;
96      call symput('yr', year(today() ) );&lt;BR /&gt;
97&lt;BR /&gt;
98      put "&amp;amp;yr.";&lt;BR /&gt;
WARNING: Apparent symbolic reference YR not resolved.&lt;BR /&gt;
99   run;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
Gday,&lt;BR /&gt;
&lt;BR /&gt;
I was wondering why the above code returns an error the &lt;I&gt;first&lt;/I&gt; time I run it?  I suspect I'm not going to understand the reason (&lt;I&gt;it resolves variables at program execution instead of macro execution&lt;/I&gt;).&lt;BR /&gt;
&lt;BR /&gt;
How can I get around this, as I need to use the value from a variable in the same datastep as the macro variable is only relevant to the current record.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Thanks.&lt;BR /&gt;
&lt;BR /&gt;
edit:&lt;BR /&gt;
&lt;BR /&gt;
This is actually what I'm trying to run:&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
%macro create_risk(section, ds, ccnt);&lt;BR /&gt;
&lt;BR /&gt;
%macro se(c);&lt;BR /&gt;
data _null_;&lt;BR /&gt;
   length tmp $200.;&lt;BR /&gt;
&lt;BR /&gt;
   tmp  = "si_&amp;amp;c.   = tmp_si;&lt;BR /&gt;
           rate_&amp;amp;c. = tmp_rate;&lt;BR /&gt;
           prem_&amp;amp;c. = tmp_prem;";&lt;BR /&gt;
&lt;BR /&gt;
   call symput('tmp2', tmp);&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
data _null_;&lt;BR /&gt;
   put "horray &amp;amp;tmp2.";&lt;BR /&gt;
run;&lt;BR /&gt;
%mend;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
data ns_risk_&amp;amp;section.;&lt;BR /&gt;
   set gins.risk_&amp;amp;ds. (obs = 2);&lt;BR /&gt;
&lt;BR /&gt;
   array si   (&amp;amp;ccnt.) si01        - si&amp;amp;ccnt.;&lt;BR /&gt;
   array code (&amp;amp;ccnt.) code01      - code&amp;amp;ccnt.;&lt;BR /&gt;
   array pc   (&amp;amp;ccnt.) PRINTCODE01 - PRINTCODE&amp;amp;ccnt.;&lt;BR /&gt;
   array r    (&amp;amp;ccnt.) RATE01      - RATE&amp;amp;ccnt. ;&lt;BR /&gt;
   array p    (&amp;amp;ccnt.) PREM01      - PREM&amp;amp;ccnt.;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
   *printcodes are usually 1 if present;&lt;BR /&gt;
   *for argis risk files they show up as 0;&lt;BR /&gt;
   do i = 1 to &amp;amp;ccnt.;&lt;BR /&gt;
      if pc&lt;I&gt; ^= . then &lt;BR /&gt;
         do;&lt;BR /&gt;
            cc = substrn(code&lt;I&gt;, 1, 4);&lt;BR /&gt;
&lt;BR /&gt;
            tmp_si   = si&lt;I&gt;;&lt;BR /&gt;
            tmp_rate = input(r&lt;I&gt;, ?? best.);;&lt;BR /&gt;
            tmp_prem = p&lt;I&gt;;;&lt;BR /&gt;
&lt;BR /&gt;
            call execute('%se(' || cc || ')' );&lt;BR /&gt;
&lt;BR /&gt;
            &amp;amp;tmp2.;&lt;BR /&gt;
            **%gg(cc );&lt;BR /&gt;
         end;&lt;BR /&gt;
   end;&lt;BR /&gt;
run;&lt;BR /&gt;
%put "yes2224" &amp;amp;tmp2.;&lt;BR /&gt;
%mend;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
%create_risk(FLST, fmlivstck,       05);&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
RISK_Policy_binder_id	RISK_FMLIVSTCK_id	CHECKBOX01	CHECKBOX02	CHECKBOX03	CHECKBOX04	CHECKBOX05	CODE01	CODE02	CODE03	CODE04	CODE05	DESC01	DESC02	DESC03	DESC04	DESC05	DISCLOADPREM	DISCORLOAD	DISCORLOADCODE	ISBLANKET	ISINIT	ISSIINIT	ISXSINIT	PREM01	PREM02	PREM03	PREM04	PREM05	RATE01	RATE02	RATE03	RATE04	RATE05	RISKSECDESCTEXT	RISKSECGRP	RISKSECGRPCODE	SI01	SI02	SI03	SI04	SI05	STNDSI01	STNDSI02	STNDSI03	STNDSI04	STNDSI05	TERRPREM	TERRRATE	TOTPREM	TOTPREMBEFADJ	TOTPREMLESSTERR	TOTSI	XSAMT01	XSAMT02	XSAMT03	XSAMT04	XSAMT05	XSCODE01	XSCODE02	XSCODE03	XSCODE04	XSCODE05	XSDESC01	XSDESC02	XSDESC03	XSDESC04	XSDESC05	XSDESCTEXT01	XSDESCTEXT02	XSDESCTEXT03	XSDESCTEXT04	XSDESCTEXT05	XTRASI01	XTRASI02	XTRASI03	XTRASI04	XTRASI05	DISCLOADRATE	PRINTSI01	PRINTSI02	PRINTSI03	PRINTSI04	PRINTSI05	PRINTCODE01	PRINTCODE02	PRINTCODE03	PRINTCODE04	PRINTCODE05	POLNO	SITNO	POLSEQ	CONVSPARE&lt;BR /&gt;
182021	14	.	.	.	.	.											.	.		.	.	.	.	.	.	.	.	.							.		.	.	.	.	.	.	.	.	.	.	.		.	.	.	.	.	.	.	.	.						.	.	.	.	.						.	.	.	.	.							.	.	.	.	.		.	.	&lt;BR /&gt;
188525	14	1	0	0	0	0	GRP101					Specified Livestock					0	.		.	0	1	1	400	.	.	.	.	0					Livestock Section	3818	FLSTFAL	5000	.	.	.	.	.	.	.	.	.	.		400	400	400	5000	0	0	.	.	.	STNDFAL	ADDLFAL				4293	4294	.	.	.	Standard Excess	Additional Excess				5000	.	.	.	.	0	$5,000					0	.	.	.	.		.	.	&lt;BR /&gt;
[/pre]&lt;BR /&gt;
^^&lt;BR /&gt;
The first two records of my data source&lt;BR /&gt;
&lt;BR /&gt;
Am not wanting a PROC TRANSPOSE solution...&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;</description>
      <pubDate>Wed, 25 May 2011 02:35:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-CALL-SYMPUT-in-same-datastep/m-p/69217#M15007</guid>
      <dc:creator>JohnT</dc:creator>
      <dc:date>2011-05-25T02:35:26Z</dc:date>
    </item>
    <item>
      <title>Re: Using CALL SYMPUT in same datastep</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-CALL-SYMPUT-in-same-datastep/m-p/69218#M15008</link>
      <description>I think you don't understand how call execute() works!&lt;BR /&gt;
There is no way you can retrieve values generated by the execute-ed process in the step where call execute() appears. That is because call execute() "submits code" which only executes once the step with call execute() finishes.&lt;BR /&gt;
However, I think you could achieve what you need with arrays for the values that your %CC macro was trying to fill si_1 - si_5, rate_1 - rate_5 and prem_1 - prem_5&lt;BR /&gt;
 &lt;BR /&gt;
At the same point, instead of [pre]call execute('%se(' || cc || ')' );[/pre] you would have code like[pre]  array  si_(&amp;amp;ccnt) ;&lt;BR /&gt;
  array rate_(&amp;amp;ccnt) ;&lt;BR /&gt;
  array prem_(&amp;amp;ccnt) ;&lt;BR /&gt;
  si_(i)   = tmp_si;&lt;BR /&gt;
  rate_(i) = tmp_rate;&lt;BR /&gt;
  prem_(i) = tmp_prem;[/pre] but since you are already using similarly named arrays, I don't see why you decided to adopt call execute(). &lt;BR /&gt;
 &lt;BR /&gt;
good luck&lt;BR /&gt;
peterC</description>
      <pubDate>Wed, 25 May 2011 06:22:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-CALL-SYMPUT-in-same-datastep/m-p/69218#M15008</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2011-05-25T06:22:45Z</dc:date>
    </item>
    <item>
      <title>Re: Using CALL SYMPUT in same datastep</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-CALL-SYMPUT-in-same-datastep/m-p/69219#M15009</link>
      <description>John,&lt;BR /&gt;
Though the problems in the upper and lower code snippets are different, they are all based on the same timing issue - the maco processor processes at a different time than the data step.  For example, let's start with a little demo code:&lt;BR /&gt;
%let SCOPE=GLOBAL;&lt;BR /&gt;
TITLE "&amp;amp;SCOPE macro variables before DATA _NULL_";&lt;BR /&gt;
proc print data=sashelp.vmacro;&lt;BR /&gt;
   where SCOPE="&amp;amp;SCOPE";&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
This produces a report:&lt;BR /&gt;
&lt;BR /&gt;
OUTPUT window:&lt;BR /&gt;
GLOBAL macro variables before DATA _NULL_ &lt;BR /&gt;
&lt;BR /&gt;
Obs   scope       name       offset  value &lt;BR /&gt;
1       GLOBAL   SCOPE   0        GLOBAL&lt;BR /&gt;
&lt;BR /&gt;
Note that the macro variable yr does not yet exist.  Now for your code:&lt;BR /&gt;
&lt;BR /&gt;
data _null_;&lt;BR /&gt;
   call symput('yr', year(today() ) );&lt;BR /&gt;
   put "&amp;amp;yr.";&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
When submitted the first time, the macro variable yr still does not exist so cannot be resolved before the DATA step is compiled.  See the SAS log:&lt;BR /&gt;
WARNING: Apparent symbolic reference YR not resolved.&lt;BR /&gt;
10   run;&lt;BR /&gt;
&amp;amp;yr.&lt;BR /&gt;
&lt;BR /&gt;
Because the macro processor could not resolve the variable yr, the DATA step compiles with the value '&amp;amp;yr.' in the PUT statement.&lt;BR /&gt;
&lt;BR /&gt;
Now, when the data step executed for the first time, it created and populated the macro variable yr.  Run this code after the first DATA _NULL_ step to prove that this is true:&lt;BR /&gt;
&lt;BR /&gt;
TITLE "&amp;amp;SCOPE macro variables after DATA _NULL_";&lt;BR /&gt;
proc print data=sashelp.vmacro;&lt;BR /&gt;
   where SCOPE="&amp;amp;SCOPE";&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
OUTPUT window:&lt;BR /&gt;
Global macro variables before DATA _NULL_ &lt;BR /&gt;
&lt;BR /&gt;
Obs  scope       name       offset   value &lt;BR /&gt;
1      GLOBAL   SCOPE    0        GLOBAL &lt;BR /&gt;
2      GLOBAL   YR           0        2011 &lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
So the second time you run your DATA step, the variable yr already exists, and it will be resolved before the DATA step gets compiled.  This will avoid the WARNING and replace the text &amp;amp;yr. in the PUT statement with 2011 as the data step compiles.  This is why the second time you run the code, you get the expected results. &lt;BR /&gt;
&lt;BR /&gt;
Hope this helps.&lt;BR /&gt;
May the SAS be with you &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;</description>
      <pubDate>Wed, 25 May 2011 14:18:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-CALL-SYMPUT-in-same-datastep/m-p/69219#M15009</guid>
      <dc:creator>SASJedi</dc:creator>
      <dc:date>2011-05-25T14:18:01Z</dc:date>
    </item>
    <item>
      <title>Re: Using CALL SYMPUT in same datastep</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-CALL-SYMPUT-in-same-datastep/m-p/69220#M15010</link>
      <description>Thanks for the responses.&lt;BR /&gt;
&lt;BR /&gt;
SASJedi, the first piece of code was an example of the problem I thought I had whcih I made up. &lt;BR /&gt;
&lt;BR /&gt;
The later code is what I care about.  Originally I didn't include it, but figured it would help me out more if I used my actual problem.&lt;BR /&gt;
&lt;BR /&gt;
I am aware that the results of CALL SYMPUT cannot be used in the same datastep, this is documented and your example/demo kind of makes sense to me, however I still can't figure out why this &lt;I&gt;feature&lt;/I&gt; is there.&lt;BR /&gt;
&lt;BR /&gt;
Peter.C, it's true, I probably don't know how to use CALL EXECUTE properly, however I have used it based on examples I have seen in the past and managed to get what I wanted.&lt;BR /&gt;
&lt;BR /&gt;
The reason why I was trying to use the CALL EXECUTE was because I want the variable to be called &lt;I&gt;SI_GRP1&lt;/I&gt; as opposed to &lt;I&gt;SI_1&lt;/I&gt;.  My issue is that the values in variable CODE01 for example isn't always the same, so if I just rename this to &lt;I&gt;SI_1&lt;/I&gt;, it won't mean the same thing for the whole table.&lt;BR /&gt;
&lt;BR /&gt;
I have that dud datastep because I thought it needed a buffer (RUN) or something to create the macro variables I was after.  As pointed out if I can't use values genereated by CALL EXECUTE then this is clearly the wrong way of doing things.  But, I'm not using values as such, I'm just creating a macro variable.&lt;BR /&gt;
&lt;BR /&gt;
Does that make sense?</description>
      <pubDate>Wed, 25 May 2011 23:04:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-CALL-SYMPUT-in-same-datastep/m-p/69220#M15010</guid>
      <dc:creator>JohnT</dc:creator>
      <dc:date>2011-05-25T23:04:39Z</dc:date>
    </item>
    <item>
      <title>Re: Using CALL SYMPUT in same datastep</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-CALL-SYMPUT-in-same-datastep/m-p/69221#M15011</link>
      <description>call symput has only three type arguments.&lt;BR /&gt;
variable name , text and text expression.&lt;BR /&gt;
So you can try this:&lt;BR /&gt;
1)call symput('yr', '2011' );&lt;BR /&gt;
&lt;BR /&gt;
2)&lt;BR /&gt;
year=year(today() );&lt;BR /&gt;
call symput('yr', year );&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Ksharp</description>
      <pubDate>Mon, 30 May 2011 09:16:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-CALL-SYMPUT-in-same-datastep/m-p/69221#M15011</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2011-05-30T09:16:09Z</dc:date>
    </item>
  </channel>
</rss>

