<?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: Passing comma-separated list to call execute in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Passing-comma-separated-list-to-call-execute/m-p/755505#M238422</link>
    <description>&lt;P&gt;Hi Chris Ah, I tried %STR outside the quotes, not inside. Good insight.&lt;/P&gt;
&lt;P&gt;However, both your statements still produce this error:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;NOTE: CALL EXECUTE generated line.
NOTE: Line generated by the CALL EXECUTE routine.
1   + %nrstr(%GetTweets2(TweetList=%str
      -
      180
ERROR 180-322: Statement is not valid or it is used out of proper order.
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 20 Jul 2021 23:32:13 GMT</pubDate>
    <dc:creator>JacquesR</dc:creator>
    <dc:date>2021-07-20T23:32:13Z</dc:date>
    <item>
      <title>Passing comma-separated list to call execute</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Passing-comma-separated-list-to-call-execute/m-p/755248#M238319</link>
      <description>&lt;P&gt;I feel like to a total dunce.&lt;/P&gt;
&lt;P&gt;I just cannot seem to grasp string encoding for macros, despite my previous questions:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Programming/Understanding-macro-compiling/m-p/650950#M195236" target="_blank"&gt;Re: Understanding macro compiling - SAS Support Communities&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Programming/Macro-quoting-for-a-url/m-p/644119#M192352" target="_blank"&gt;Solved: Re: Macro quoting for a url - SAS Support Communities&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Programming/CALL-SYMPUT-within-a-macro-generated-using-CALL-EXECUTE/m-p/745491#M233684" target="_blank"&gt;Solved: Re: CALL SYMPUT within a macro generated using CAL... - SAS Support Communities&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;In short, I am using (or hoping to use) the Twitter API to retrieve tweets.&lt;/P&gt;
&lt;P&gt;&lt;A href="https://developer.twitter.com/en/docs/twitter-api/tweets/lookup/api-reference/get-tweets" target="_blank"&gt;Tweet lookup - GET /2/tweets | Docs | Twitter Developer Platform&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;The API allows me to specify up to 100 Tweet IDs in a comma-separated list with no spaces.&lt;/P&gt;
&lt;P&gt;This is a sample API call from the abovementioned page:&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;"&lt;A href="https://api.twitter.com/2/tweets?ids=1261326399320715264,1278347468690915330" target="_blank"&gt;https://api.twitter.com/2/tweets?ids=1261326399320715264,1278347468690915330&lt;/A&gt;"&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;I have created a dataset with the variable&amp;nbsp;TweetList that is a list of up to 100 of these IDs, separated by commas.&lt;/P&gt;
&lt;P&gt;So far, so good.&lt;/P&gt;
&lt;P&gt;Now for each row in this dataset, I want to send out the API call, get and parse the result, and then append it to a dataset.&lt;/P&gt;
&lt;P&gt;I won't bore you with the details of the whole macro--the code within works when I run it with a single Tweet ID, and I adapted code from here to create it:&amp;nbsp;&lt;A href="https://blogs.sas.com/content/sascom/2013/12/12/how-to-import-twitter-tweets-in-sas-data-step-using-oauth-2-authentication-style/" target="_blank"&gt;https://blogs.sas.com/content/sascom/2013/12/12/how-to-import-twitter-tweets-in-sas-data-step-using-oauth-2-authentication-style/&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The macro header is:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%MACRO GetTweets(TweetList=,N=);
&amp;nbsp; &amp;nbsp;%let JSON_TWEET_FILE=&amp;amp;OutputPath.ResponseContent&amp;amp;N..txt;
&amp;nbsp; &amp;nbsp;%let CSV_TWEET_FILE=&amp;amp;OutputPath.ResponseContent&amp;amp;N..csv;
&amp;nbsp; &amp;nbsp;FILENAME response &amp;amp;JSON_TWEET_FILE.;
...
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;N is just so that I can store the results in a sequence of data files, one for each run.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If it's any help, the total length (using LENGTHN) for TweetList varies between 1903 and 1923 characters.&lt;/P&gt;
&lt;P&gt;If you want to test my code below, this simplified macro should work:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%MACRO GetTweets(TweetList=,N=);
%PUT &amp;amp;TweetList;
%PUT &amp;amp;N;
%MEND;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I actually have two problems. I will post two variations of the code, and the errors raised, to highlight the issues. In the code below I replace real Tweet IDs with the IDs from Twitter's example.&lt;/P&gt;
&lt;P&gt;First, despite my defining a length of $4000. for the statement, it is not accepting the whole list:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA _NULL_;
LENGTH _call $4000.;
SET TWITTER.NootropicTweetListsForAPI;
	 _call='%nrstr('||'%GetTweets(TweetList='||%NRSTR(TweetList)||',N='||_N_||'));';
	PUT _call=;
	CALL EXECUTE(_call);
RUN;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;NOTE: Numeric values have been converted to character values at the places given by: (Line):(Column).
      573:70
_call=%nrstr(%GetTweets(TweetList=&lt;SPAN&gt;1261326399320715264,1278347468690915330&lt;/SPAN&gt;,&amp;lt;Lots more IDs&amp;gt;,&lt;SPAN&gt;1261326399320715264,1278347468690915330&lt;/SPAN&gt;
ERROR: Expected close parenthesis after macro function invocation not found.
NOTE: The SAS System stopped processing this step because of errors.
NOTE: There were 625 observations read from the data set TWITTER.NOOTROPICTWEETLISTSFORAPI.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds

NOTE: CALL EXECUTE generated line.
ERROR: All positional parameters must precede keyword parameters.
1   + %GetTweets
NOTE: Line generated by the CALL EXECUTE routine.
2   +(TweetList=&lt;SPAN&gt;1261326399320715264,1278347468690915330,1261326399320715264,1278347468690915330,....&lt;/SPAN&gt;
                                                        ------------------
                                                        180
2  !+&lt;SPAN&gt;1261326399320715264,1278347468690915330&lt;/SPAN&gt;
ERROR 180-322: Statement is not valid or it is used out of proper order.
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If I reduce the length passed through, the whole string is created, but the problem surrounding the comma separating the Tweet IDs remains:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA _NULL_;
LENGTH _call $4000.;
SET TWITTER.NootropicTweetListsForAPI;
	_call='%nrstr('||'%GetTweets(TweetList='||%NRSTR(SUBSTRN(TweetList,1,58))||',N='||_N_||'));';
	PUT _call=;
	CALL EXECUTE(_call);
RUN;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;NOTE: Numeric values have been converted to character values at the places given by: (Line):(Column).
      582:83
_call=%nrstr(%GetTweets(TweetList=&lt;SPAN&gt;1261326399320715264,1278347468690915330,1261326399320715264&lt;/SPAN&gt;,N=           1));
NOTE: There were 625 observations read from the data set TWITTER.NOOTROPICTWEETLISTSFORAPI.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds

NOTE: CALL EXECUTE generated line.
ERROR: All positional parameters must precede keyword parameters.
NOTE: Line generated by the CALL EXECUTE routine.
1   + %GetTweets(TweetList=&lt;SPAN&gt;1261326399320715264,1278347468690915330,1261326399320715264&lt;/SPAN&gt;,N=           1);
                                                                   ------------------
                                                                   180

ERROR 180-322: Statement is not valid or it is used out of proper order.&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Any help would be appreciated. And perhaps an explanation of what I am missing that is keeping me from figuring this out, even though this is evidently not the first time I have grappled with this topic.&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 20 Jul 2021 07:45:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Passing-comma-separated-list-to-call-execute/m-p/755248#M238319</guid>
      <dc:creator>JacquesR</dc:creator>
      <dc:date>2021-07-20T07:45:59Z</dc:date>
    </item>
    <item>
      <title>Re: Passing comma-separated list to call execute</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Passing-comma-separated-list-to-call-execute/m-p/755251#M238322</link>
      <description>&lt;P&gt;Make your life easier by using another delimiter in a string you want to use as a macro parameter.&lt;/P&gt;
&lt;P&gt;If you use "|" as delimiter, you can use&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
length tweetlist $32767;
tweetlist = translate("&amp;amp;tweetlist.",",","|");
call symputx("tweetlist",tweetlist,"l");
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;in the macro to create the comma-separated list where needed.&lt;/P&gt;</description>
      <pubDate>Tue, 20 Jul 2021 08:01:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Passing-comma-separated-list-to-call-execute/m-p/755251#M238322</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-07-20T08:01:29Z</dc:date>
    </item>
    <item>
      <title>Re: Passing comma-separated list to call execute</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Passing-comma-separated-list-to-call-execute/m-p/755266#M238335</link>
      <description>&lt;P&gt;You could try&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; _CALL='%nrstr('||'%GetTweets(TweetList=%str('||TWEETLIST||'),N='||_N_||'));';&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;or even&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; _CALL=catt( '%GetTweets(TweetList=%str(', TWEETLIST, '), N=',  _N_, ');' );&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 20 Jul 2021 09:08:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Passing-comma-separated-list-to-call-execute/m-p/755266#M238335</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2021-07-20T09:08:55Z</dc:date>
    </item>
    <item>
      <title>Re: Passing comma-separated list to call execute</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Passing-comma-separated-list-to-call-execute/m-p/755276#M238338</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So something like this?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%MACRO GetTweets2(TweetList=,N=);
%PUT &amp;amp;TweetList;
%PUT &amp;amp;N;
%LET TweetList2=%SYSFUNC(TRANSTRN("&amp;amp;TweetList","|",","));
DATA _NULL_;
LENGTH tmp $4000.;
tmp=TRANSTRN("&amp;amp;TweetList","|",",");
call symputx("TweetList2",tmp,"l");
run;
%PUT &amp;amp;TweetList2;
%MEND;
DATA _NULL_;
LENGTH _call $4000.;
SET TWITTER.NootropicTweetListsForAPI;
	TweetList=TRANSTRN(TweetList,",","|");
 _call='%nrstr('||'%GetTweets2(TweetList='||%NRSTR(TRIMN(TweetList))||',N='||_N_||'));';
	PUT _call=;
	CALL EXECUTE(_call);
RUN;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Why does the sysfunc not work?&lt;/P&gt;
&lt;P&gt;I get a couple of these, but the put statements seem to produce the right result:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;NOTE: The quoted string currently being processed has become more than 262 characters long.  You might have unbalanced quotation marks.&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 20 Jul 2021 09:30:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Passing-comma-separated-list-to-call-execute/m-p/755276#M238338</guid>
      <dc:creator>JacquesR</dc:creator>
      <dc:date>2021-07-20T09:30:44Z</dc:date>
    </item>
    <item>
      <title>Re: Passing comma-separated list to call execute</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Passing-comma-separated-list-to-call-execute/m-p/755291#M238346</link>
      <description>&lt;P&gt;Make sure that the variable tweetlist has pipe characters instead of commas, then simplify the_call variable:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;_call='%nrstr(%GetTweets2(TweetList='||trim(TweetList)||',N='||strip(put(_N_,best.))||'));';&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 20 Jul 2021 10:42:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Passing-comma-separated-list-to-call-execute/m-p/755291#M238346</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-07-20T10:42:42Z</dc:date>
    </item>
    <item>
      <title>Re: Passing comma-separated list to call execute</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Passing-comma-separated-list-to-call-execute/m-p/755505#M238422</link>
      <description>&lt;P&gt;Hi Chris Ah, I tried %STR outside the quotes, not inside. Good insight.&lt;/P&gt;
&lt;P&gt;However, both your statements still produce this error:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;NOTE: CALL EXECUTE generated line.
NOTE: Line generated by the CALL EXECUTE routine.
1   + %nrstr(%GetTweets2(TweetList=%str
      -
      180
ERROR 180-322: Statement is not valid or it is used out of proper order.
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 20 Jul 2021 23:32:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Passing-comma-separated-list-to-call-execute/m-p/755505#M238422</guid>
      <dc:creator>JacquesR</dc:creator>
      <dc:date>2021-07-20T23:32:13Z</dc:date>
    </item>
    <item>
      <title>Re: Passing comma-separated list to call execute</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Passing-comma-separated-list-to-call-execute/m-p/755507#M238424</link>
      <description>&lt;P&gt;That's a different error, linked to something else you do. The comma-delimited list works.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro GetTweets(TweetList=,N=); %put ====&amp;gt; &amp;amp;=Tweetlist &amp;amp;=N; %mend;
 data _null_;
   TWEETLIST='a,b,c';
  _CALL='%nrstr('||'%GetTweets(TweetList=%str('||TWEETLIST||'),N='||_N_||'));';
   call execute(_CALL);
  _CALL=catt( '%GetTweets(TweetList=%str(', TWEETLIST, '), N=',  _N_, ');' );
  call execute(_CALL);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;32          data _null_;
33            TWEETLIST='a,b,c';
34           _CALL='%nrstr('||'%GetTweets(TweetList=%str('||TWEETLIST||'),N='||_N_||'));';
35            call execute(_CALL);
36           _CALL=catt( '%GetTweets(TweetList=%str(', TWEETLIST, '), N=',  _N_, ');' );
37           call execute(_CALL);
38         run;

NOTE: Numeric values have been converted to character values at the places given by: (Line):(Column).
      34:69   
====&amp;gt; TWEETLIST=a,b,c N=1
NOTE: DATA statement used (Total process time):
      real time           0.11 seconds
      user cpu time       0.01 seconds
      system cpu time     0.01 seconds
      memory              241.34k
      OS Memory           17748.00k
      Timestamp           21/07/2021 11:41:34 AM
      Step Count                        35  Switch Count  48
      

NOTE: CALL EXECUTE generated line.
1         + %GetTweets(TweetList=%str(a,b,c),N=           1);
====&amp;gt; TWEETLIST=a,b,c N=1
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 20 Jul 2021 23:42:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Passing-comma-separated-list-to-call-execute/m-p/755507#M238424</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2021-07-20T23:42:11Z</dc:date>
    </item>
    <item>
      <title>Re: Passing comma-separated list to call execute</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Passing-comma-separated-list-to-call-execute/m-p/755513#M238429</link>
      <description>&lt;P&gt;So your error is because you are generating this macro call:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%GetTweets(TweetList=1261326399320715264,1278347468690915330,....&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Which is clearly invalid.&amp;nbsp; You are passing the first parameter value,&amp;nbsp;1261326399320715264, by name and the following that with trying to pass another parameter value by position.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You don't show either how you are generating the dataset variable,&amp;nbsp;TweetList, or what the macro %GETTWEETS() is expects in the input parameter TWEETLIST.&amp;nbsp; But it will work much easier if you replace the commas in your list of tweets with some other character.&amp;nbsp; Since the values look to be digit strings just use spaces.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There is normally no advantage to adding the %NRSTR() around the parameter values, and it can make somethings hard, like referencing existing macro variables.&amp;nbsp; Just wrap the %macroname part in the %NRSTR() macro function so that the macro does not run while CALL EXECUTE() is running and instead runs when the code is pulled back off the stack after the data step ends.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  set twitter.nootropictweetlistsforapi;
  call execute(cats('%nrstr(%gettweets)(tweetlist=',translate(tweetlist,' ',','),',n=',_n_,')'));
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 21 Jul 2021 00:31:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Passing-comma-separated-list-to-call-execute/m-p/755513#M238429</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-07-21T00:31:28Z</dc:date>
    </item>
  </channel>
</rss>

