<?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: SCAN function call has too many arguments in dataset in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SCAN-function-call-has-too-many-arguments-in-dataset/m-p/348572#M273433</link>
    <description>&lt;P&gt;When SAS macro generates code the generated code is passed to regular SAS for processing. &amp;nbsp;So you need to generate code that SAS can process.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In SAS code a string literal is enclosed in quotes.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;value=scan("&amp;amp;RankGroupPeriod",i,'+');&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or you could change to using the SYMGET() function instead.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;value=scan(symget('RankGroupPeriod'),i,'+');&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 10 Apr 2017 02:32:25 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2017-04-10T02:32:25Z</dc:date>
    <item>
      <title>SCAN function call has too many arguments in dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SCAN-function-call-has-too-many-arguments-in-dataset/m-p/348571#M273432</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am having an issue separating a string with a particular delimiter. I keep getting this error&lt;/P&gt;&lt;P&gt;"The SCAN function call has too many arguments."&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;amp;RankGroupPeriod - is created&amp;nbsp;by reading from a dataset and looks like "CR_Rank,QR_Rank,WC_Rank+FDR_Rank,BQ_Rank,NCD_Rank+ ..etc..."&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I guess the value of&amp;nbsp;&lt;SPAN&gt;&amp;amp;RankGroupPeriod is too large for scan function. Is there another way to separte&amp;nbsp;&amp;amp;RankGroupPeriod by + and create a column in the dataset for each of the values ?&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;proc sql noprint; &lt;BR /&gt; select comb into :RankGroupPeriod separated by '+'&lt;BR /&gt; from testcombination;&lt;BR /&gt;quit;&lt;BR /&gt;&lt;BR /&gt;proc sql noprint; &lt;BR /&gt; select count(comb) into :countCombinations&lt;BR /&gt; from testcombination;&lt;BR /&gt;quit;&lt;BR /&gt;&lt;BR /&gt;%put RankGroupPeriod = &amp;amp;RankGroupPeriod;/*list of comma separated groups of 3 rankGroups*/&lt;BR /&gt;%put countCombinations = &amp;amp;countCombinations;/* number of combinations in table*/&lt;BR /&gt;&lt;BR /&gt;data comp4a; 
	  set comp4;
	  by year gvkey;
	  do i = 1 to &amp;amp;countCombinations;
			/*get values from list,one by one, separtated by '.' */
			/* each value would look like this CR_Rank,QR_Rank,WC_Rank */
		    value=scan(&amp;amp;RankGroupPeriod,i,'+');
			output;
	  end;
run;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 10 Apr 2017 02:25:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SCAN-function-call-has-too-many-arguments-in-dataset/m-p/348571#M273432</guid>
      <dc:creator>scrapex87</dc:creator>
      <dc:date>2017-04-10T02:25:13Z</dc:date>
    </item>
    <item>
      <title>Re: SCAN function call has too many arguments in dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SCAN-function-call-has-too-many-arguments-in-dataset/m-p/348572#M273433</link>
      <description>&lt;P&gt;When SAS macro generates code the generated code is passed to regular SAS for processing. &amp;nbsp;So you need to generate code that SAS can process.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In SAS code a string literal is enclosed in quotes.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;value=scan("&amp;amp;RankGroupPeriod",i,'+');&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or you could change to using the SYMGET() function instead.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;value=scan(symget('RankGroupPeriod'),i,'+');&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 10 Apr 2017 02:32:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SCAN-function-call-has-too-many-arguments-in-dataset/m-p/348572#M273433</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-04-10T02:32:25Z</dc:date>
    </item>
    <item>
      <title>Re: SCAN function call has too many arguments in dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SCAN-function-call-has-too-many-arguments-in-dataset/m-p/348573#M273434</link>
      <description>&lt;P&gt;Thank you Tom. That fixed the issue. But, now I am getting the following if I pass the value in a mean function.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I guess Scan is returning a numeric data and i'm mean function is expecting a string.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;NOTE: Invalid numeric data, value='ROA_Rank,WC_Rank,NM_Rank' , at line 3554 column 20.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data comp4a; 
	  set comp4;
	  by year gvkey;
	  do i = 1 to &amp;amp;countCombinations;
			/*get values from list,one by one, separtated by '.' */
			/* each value would look like this CR_Rank,QR_Rank,WC_Rank */
		    value=scan(symget('RankGroupPeriod'),i,'+');
			AggRank= mean(value);
			output;
	  end;
run;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 10 Apr 2017 02:45:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SCAN-function-call-has-too-many-arguments-in-dataset/m-p/348573#M273434</guid>
      <dc:creator>scrapex87</dc:creator>
      <dc:date>2017-04-10T02:45:32Z</dc:date>
    </item>
    <item>
      <title>Re: SCAN function call has too many arguments in dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SCAN-function-call-has-too-many-arguments-in-dataset/m-p/348575#M273435</link>
      <description>&lt;P&gt;As&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;mentioned, you need to enclose the macro variable in quotes. Is there a limit to macro variable size? YES. Approximately 64K.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If your list contains more characters than that you need an alternative solution.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How do you plan to use it .. what are you trying to do? There are always alternatives, but one can't suggest them without knowing the papameters and goal(s).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;</description>
      <pubDate>Mon, 10 Apr 2017 02:47:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SCAN-function-call-has-too-many-arguments-in-dataset/m-p/348575#M273435</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-04-10T02:47:40Z</dc:date>
    </item>
    <item>
      <title>Re: SCAN function call has too many arguments in dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SCAN-function-call-has-too-many-arguments-in-dataset/m-p/348576#M273436</link>
      <description>&lt;P&gt;Value is a character variable. You either need to convert this to a numeric or change your logic - I'm not sure what you're trying to do but I suspect it's being over complicated.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 10 Apr 2017 02:47:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SCAN-function-call-has-too-many-arguments-in-dataset/m-p/348576#M273436</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-04-10T02:47:56Z</dc:date>
    </item>
    <item>
      <title>Re: SCAN function call has too many arguments in dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SCAN-function-call-has-too-many-arguments-in-dataset/m-p/348577#M273437</link>
      <description>&lt;P&gt;The ultimate goal is to compute the mean/average of a list of columns that is being defined by the "RankGroupPeriod" variable.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;The RankGroupPeriod looks like this "CR_Rank,QR_Rank,WC_Rank+FDR_Rank,BQ_Rank,NCD_Rank&lt;/SPAN&gt;&lt;SPAN&gt;+ ..etc..."&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;The comma sepparated values are column names in the dataset "comp4". So, for each 3 of those columns, I want to compute the average value and put it in a new column.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;So, for each iteration the value would be "CR_Rank,QR_Rank,WC_Rank".&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;If you put that value into the mean(CR_Rank,QR_Rank,WC_Rank) function it should give the average for those columns and create a new column for each iteration I.E. AggRank_CR_Rank,QR_Rank,WC_Rank.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Not sure if there is another way of doing it.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data comp4a; 
	  set comp4;
	  by year gvkey;
	  do i = 1 to &amp;amp;countCombinations;
			/*get values from list,one by one, separtated by '.' */
			/* each value would look like this CR_Rank,QR_Rank,WC_Rank */
		    value=scan(symget('RankGroupPeriod'),i,'+');
			AggRank_value= mean(value);/*name the column based on the value*/
			output;
	  end;
run;&lt;/PRE&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 10 Apr 2017 02:57:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SCAN-function-call-has-too-many-arguments-in-dataset/m-p/348577#M273437</guid>
      <dc:creator>scrapex87</dc:creator>
      <dc:date>2017-04-10T02:57:34Z</dc:date>
    </item>
    <item>
      <title>Re: SCAN function call has too many arguments in dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SCAN-function-call-has-too-many-arguments-in-dataset/m-p/348581#M273438</link>
      <description>&lt;P&gt;Sounds to me like you want proc means, proc summary or proc sql. You can use a by statement with the first two, and a group by with proc sql.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you just want the means, or do you want them attached to each record in your data set?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 10 Apr 2017 03:13:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SCAN-function-call-has-too-many-arguments-in-dataset/m-p/348581#M273438</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-04-10T03:13:33Z</dc:date>
    </item>
    <item>
      <title>Re: SCAN function call has too many arguments in dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SCAN-function-call-has-too-many-arguments-in-dataset/m-p/348582#M273439</link>
      <description>&lt;P&gt;Then the same method used in your previous question is applicable.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SYMGET is not the correct approach, VVALUEX will work.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 10 Apr 2017 03:14:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SCAN-function-call-has-too-many-arguments-in-dataset/m-p/348582#M273439</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-04-10T03:14:46Z</dc:date>
    </item>
    <item>
      <title>Re: SCAN function call has too many arguments in dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SCAN-function-call-has-too-many-arguments-in-dataset/m-p/348583#M273440</link>
      <description>&lt;P&gt;If you want to take the MEAN() of variables then you need to use the MEAN() function and not use a text function like SCAN().&lt;/P&gt;
&lt;P&gt;If I understand it right you have the following two macro variables.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let list=CR_Rank,QR_Rank,WC_Rank+FDR_Rank,BQ_Rank,NCD_Rank;
%let n=2;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And since N=2 you want to calculate two means. This means you need to generate two MEAN() function calls.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;value = mean(CR_Rank,QR_Rank,WC_Rank);
...
value = mean(FDR_Rank,BQ_Rank,NCD_Rank);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You could do it with a MACRO %DO loop, but you can't do it with a data step DO loop.&lt;/P&gt;
&lt;P&gt;Another way to generate code is to just write it to a file and use %INCLUDE where you want to run it.&lt;/P&gt;
&lt;P&gt;So if your metadata looks like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data metadata;
  input varlist $80.;
cards;
CR_Rank,QR_Rank,WC_Rank
FDR_Rank,BQ_Rank,NCD_Rank
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You could use a simple data step to write the code you need.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename code temp;
data _null_;
  set metadata;
  put 'value=mean(' varlist ');'
    / 'output;'
  ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You could then use that code later to process your data.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want ;
  set have ;
%include code / source2;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;In general it is much easier to work with dataset and text files than macro variables and macro logic.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Probably your metadata looks more like (or should look like this).&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data metadata;
  input group varname $32.;
cards;
1 CR_Rank
1 QR_Rank
1 WC_Rank
2 FDR_Rank
2 BQ_Rank
2 NCD_Rank
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then your code generation step would look more like this.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename code temp;
data _null_;
  set metadata;
  by group;
  if first.group then put group= ';' / 'value=mean(.' @ ;
  put ',' varname @;
  if last.group then put ');' / 'output;' ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then the groups could have different numbers of variables and you would get code like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;group=1;
value = mean(.,CR_Rank,QR_Rank,WC_Rank);
output;
group=2;
value = mean(.,FDR_Rank,BQ_Rank,NCD_Rank);
output;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 10 Apr 2017 03:34:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SCAN-function-call-has-too-many-arguments-in-dataset/m-p/348583#M273440</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-04-10T03:34:22Z</dc:date>
    </item>
    <item>
      <title>Re: SCAN function call has too many arguments in dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SCAN-function-call-has-too-many-arguments-in-dataset/m-p/348585#M273441</link>
      <description>&lt;P&gt;vvaluex did the trick. Thank you.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 10 Apr 2017 03:37:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SCAN-function-call-has-too-many-arguments-in-dataset/m-p/348585#M273441</guid>
      <dc:creator>scrapex87</dc:creator>
      <dc:date>2017-04-10T03:37:50Z</dc:date>
    </item>
  </channel>
</rss>

