<?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: programming within proc cas in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/programming-within-proc-cas/m-p/966108#M376026</link>
    <description>&lt;P&gt;I've solved it by adding a fake numeric variable whose name has length 32.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;this ensures the loc function working properly.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 08 May 2025 20:37:03 GMT</pubDate>
    <dc:creator>acordes</dc:creator>
    <dc:date>2025-05-08T20:37:03Z</dc:date>
    <item>
      <title>programming within proc cas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/programming-within-proc-cas/m-p/966094#M376020</link>
      <description>&lt;P&gt;I'm creating my own cas actions, and the result is as expected except that the loc function sometimes returns -1 despite the stripped value should be found in the stripped lookup table.&lt;/P&gt;
&lt;P&gt;I've created a simplified version of my challenge leaving only the cas actions result part with the loc functionality.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is the link to the documentation.&amp;nbsp;&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/v_062/proccas/p01s21os7idn2ln1aaefthmtjqru.htm" target="_self"&gt;https://documentation.sas.com/doc/en/pgmsascdc/v_062/proccas/p01s21os7idn2ln1aaefthmtjqru.htm&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
%let namer=ts;
%let namer2=a123456789b123456789c123456789;
%let namer3=a123456789b123456789c123456789d1;

data casuser.cars;
set sashelp.cars;
format &amp;amp;namer &amp;amp;namer2 datetime20. ;
&amp;amp;namer=intnx('dtminutes', datetime(), rand('integer', -1000, 0));
&amp;amp;namer2=&amp;amp;namer;
&amp;amp;namer3=put(rand('uniform', 0, 1), best12.);
run;

%let casy=cars;
%let liby=casuser;


cas mySession sessopts=(caslib="&amp;amp;liby");

ods escapechar='^';
proc cas;

	table.columninfo result=r /table="&amp;amp;casy";
      	columns = '';
		search_cols='';
      	do i = 1 to r.columninfo.nrows;
			if index(UPCASE(r['columninfo'][i,7]), 'DATETIME')  THEN do;
         		symput('col', ifc(prxmatch('m/\s/i',r[1,i].column), '''||r[1,i].column||''n', r[1,i].column));
         		columns = columns||' '||symget('col');
         		search_cols = strip(search_cols||'|'||symget('col'));
			end;
      end;
      	symput('ok_list', substrn(search_cols,2,length(search_cols)-1));
      	symput('varlist', substrn(columns,2,length(columns)-1));

		print "&amp;amp;ok_list.";
run;

   simple.summary result=sumres / 
      subset={'min', 'max'},
		table="&amp;amp;casy";

	sumlist=findtable(sumres);

do k=1 to dim(sumres.summary);
		print quote(sumres.summary[k, 1]);
end;

    simple.distinct result=dist /
        table="&amp;amp;casy";

do l=1 to dim(dist.distinct);
		print quote(dist.distinct[l, 1]);
end;

run;

	do i=1 to dim(dist.distinct);
			if prxmatch(cats('m/\b', symget('ok_list'), '\b/i'), strip(dist.distinct[i, 1]))  then do;
					help=strip(dist.distinct[i, 1]);
						print quote(help);
					j=loc(sumlist, 'column', help);
			if j&amp;lt;1 then do;
						help=dist.distinct[i, 1];
							print quote(help);
						j=loc(sumlist, 'column', help);
			end;
						print j;
		end;

	end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And the log shows the problem:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="PIC.png" style="width: 542px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/106813i1E53137EE855F3F4/image-size/large?v=v2&amp;amp;px=999" role="button" title="PIC.png" alt="PIC.png" /&gt;&lt;/span&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="pic1.png" style="width: 880px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/106814i3FD07515D85E86ED/image-size/large?v=v2&amp;amp;px=999" role="button" title="pic1.png" alt="pic1.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The loc function does not return a value for the variable 'ts'n because the distinct action returns a wider width for the column name than the summary action.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32"&gt;@BrunoMueller&lt;/a&gt;&amp;nbsp;to the rescue &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&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;</description>
      <pubDate>Thu, 08 May 2025 17:52:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/programming-within-proc-cas/m-p/966094#M376020</guid>
      <dc:creator>acordes</dc:creator>
      <dc:date>2025-05-08T17:52:53Z</dc:date>
    </item>
    <item>
      <title>Re: programming within proc cas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/programming-within-proc-cas/m-p/966108#M376026</link>
      <description>&lt;P&gt;I've solved it by adding a fake numeric variable whose name has length 32.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;this ensures the loc function working properly.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 08 May 2025 20:37:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/programming-within-proc-cas/m-p/966108#M376026</guid>
      <dc:creator>acordes</dc:creator>
      <dc:date>2025-05-08T20:37:03Z</dc:date>
    </item>
    <item>
      <title>Re: programming within proc cas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/programming-within-proc-cas/m-p/967086#M376283</link>
      <description>&lt;P&gt;Glad you found a solution. It seems that the LOC function uses char values and if the length does not match it will not be found.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Another way of doing this, would be to get the values into an array and then use this expression:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;newArray = columnNamesArray &amp;amp; lookupArray;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This will return only common values in both arrays, see &lt;A href="https://go.documentation.sas.com/doc/en/pgmsascdc/v_063/caslpg/p05d2i2ery1r4dn126z88d2vns1g.htm" target="_blank" rel="noopener"&gt;CASL Array Operrators&lt;/A&gt; for more details. the length of the values does not seem to matter. Here is the code I used for testing:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let namer=ts;
%let namer2=a123456789b123456789c123456789;
%let namer3=a123456789b123456789c123456789d1;

%let casy=cars;
%let liby=casuser;

cas mySession sessopts=(caslib="&amp;amp;liby");
libname casuser cas caslib="casuser";

data casuser.cars;
  set sashelp.cars;
  format &amp;amp;namer &amp;amp;namer2 datetime20. ;
  &amp;amp;namer=intnx('dtminutes', datetime(), rand('integer', -1000, 0));
  &amp;amp;namer2=&amp;amp;namer;
  &amp;amp;namer3=put(rand('uniform', 0, 1), best12.);
run;

proc cas;
  table.columninfo result=r / table="&amp;amp;casy";
  columns = '';
  search_cols='';
  /* array with names to search for */
  search_cols_array = {};
  
  do i = 1 to r.columninfo.nrows;
    if index(UPCASE(r['columninfo'][i,7]), 'DATETIME')  THEN do;
      symput('col', ifc(prxmatch('m/\s/i',r[1,i].column), '''||r[1,i].column||''n', r[1,i].column));
      /* fill array with search values */
      search_cols_array = search_cols_array + r[1,i].column;
      columns = columns||' '||symget('col');
      search_cols = strip(search_cols||'|'||symget('col'));
    end;
  end;
  print(note) "search_cols_array=" search_cols_array;
  symput('ok_list', substrn(search_cols,2,length(search_cols)-1));
  symput('varlist', substrn(columns,2,length(columns)-1));
run;
  %put &amp;amp;=ok_list;
  %put &amp;amp;=varlist;
run;
  simple.summary result=sumres / subset={'min', 'max'}, table="&amp;amp;casy";
/*   describe sumres.summary; */
  sumlist=findtable(sumres);
  colNames = GETCOLUMN(sumlist, "Column");
  print(note) "colNames=" colNames;
  commonArray = colNames &amp;amp; search_cols_array;
  print(note) "commonArray summary=" commonArray;
run;
  simple.distinct result=dist / table="&amp;amp;casy";
  describe dist.distinct;
  colNames = GETCOLUMN(dist.distinct, 1);
  print(note) "colNames=" colNames;
  commonArray = colNames &amp;amp; search_cols_array;
  print(note) "commonArray distinct=" commonArray;
run;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 21 May 2025 08:54:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/programming-within-proc-cas/m-p/967086#M376283</guid>
      <dc:creator>BrunoMueller</dc:creator>
      <dc:date>2025-05-21T08:54:56Z</dc:date>
    </item>
  </channel>
</rss>

