<?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: How to Scan with Delimiters, without getting blanks or duplicates in the output in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-Scan-with-Delimiters-without-getting-blanks-or-duplicates/m-p/831708#M328704</link>
    <description>&lt;P&gt;If you have Y1 or Z2 ...........&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;Data Have ;
  infile datalines dsd ;
  input formula : $30. ;
  datalines ;
X1 / X2 + X4
(X1 + X2) / (X3 - X1) * 2
;
Run ;

data temp;
 set have;
 id+1;
 pid=prxparse('/[a-z]\d+/i');
 start=1;end=length(formula);
 call prxnext(pid,start,end,formula,p,l);
 do while(p&amp;gt;0);
  temp=substr(formula,p,l);
  output;
  call prxnext(pid,start,end,formula,p,l);
 end;
keep id temp;
run;
proc sort data=temp nodupkey;by id temp;run;
proc transpose data=temp out=want(drop=_:) prefix=C;
by id;
var temp;
run;&lt;/PRE&gt;</description>
    <pubDate>Sun, 04 Sep 2022 10:35:25 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2022-09-04T10:35:25Z</dc:date>
    <item>
      <title>How to Scan with Delimiters, without getting blanks or duplicates in the output</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Scan-with-Delimiters-without-getting-blanks-or-duplicates/m-p/831701#M328700</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;What is the best solution for scanning a formula&lt;U&gt; without&lt;/U&gt; getting in the output&amp;nbsp; &amp;nbsp;-&amp;nbsp; c(I) columns (I = 1,2,3..)&lt;/P&gt;&lt;P&gt;a.&amp;nbsp;Null values&amp;nbsp;(for example in the available data we have C3 and C4 with null values)&lt;/P&gt;&lt;P&gt;b.&amp;nbsp;Duplicate values (for example X1 appears twice in the second line of have data )&lt;BR /&gt;c. Digits (the digit 2 was dropped succesfully from available data )&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Data Have ;&lt;BR /&gt;infile datalines dsd ;&lt;BR /&gt;input formula : $30. ;&lt;BR /&gt;datalines ;&lt;BR /&gt;X1 / X2 + X4&lt;BR /&gt;(X1 + X2) / (X3 - X1) * 2&lt;BR /&gt;;&lt;BR /&gt;Run ;&lt;/P&gt;&lt;P&gt;data Available ;&lt;BR /&gt;set Have ;&lt;BR /&gt;delims = '+-/*()' ;&lt;BR /&gt;Array ccc_ [10] $32 c1-c10 ;&lt;BR /&gt;do i = 1 to 10 ;&lt;BR /&gt;if countc(scan(formula, i, delims),'X') &amp;gt; 0&lt;BR /&gt;ccc_[i] = scan(formula, i, delims) ;&lt;BR /&gt;end ;&lt;BR /&gt;drop delims i ;&lt;BR /&gt;run ;&lt;BR /&gt;&lt;BR /&gt;Data Want ;&lt;BR /&gt;infile datalines dsd ;&lt;BR /&gt;input C1 $3. C2 $3. C3 $3. ;&lt;BR /&gt;datalines ;&lt;BR /&gt;X1 X2 X4&lt;BR /&gt;X1 X2 X3&lt;BR /&gt;;&lt;BR /&gt;Run ;&lt;/P&gt;</description>
      <pubDate>Sun, 04 Sep 2022 06:34:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Scan-with-Delimiters-without-getting-blanks-or-duplicates/m-p/831701#M328700</guid>
      <dc:creator>J111</dc:creator>
      <dc:date>2022-09-04T06:34:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to Scan with Delimiters, without getting blanks or duplicates in the output</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Scan-with-Delimiters-without-getting-blanks-or-duplicates/m-p/831703#M328702</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ops ... added "then" below&lt;/P&gt;&lt;P&gt;data Available ; set Have ; delims = '+-/*()' ; Array ccc_ [10] $32 c1-c10 ; do i = 1 to 10 ; if countc(scan(formula, i, delims),'X') &amp;gt; 0 &lt;U&gt;then&lt;/U&gt; ccc_[i] = scan(formula, i, delims) ; end ; drop delims i ; run ;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 04 Sep 2022 06:42:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Scan-with-Delimiters-without-getting-blanks-or-duplicates/m-p/831703#M328702</guid>
      <dc:creator>J111</dc:creator>
      <dc:date>2022-09-04T06:42:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to Scan with Delimiters, without getting blanks or duplicates in the output</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Scan-with-Delimiters-without-getting-blanks-or-duplicates/m-p/831706#M328703</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/386728"&gt;@J111&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The following should work. I had some trouble getting the sorting right until I noticed that some of the C1-C10 variables had leading blanks.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*** Your code ***/

Data Have ;
  infile datalines dsd ;
  input formula : $30. ;
  datalines ;
X1 / X2 + X4
(X1 + X2) / (X3 - X1) * 2
;
Run ;

data Available ;
  set Have ;
  delims = '+-/*()' ;
  Array ccc_ [10] $32 c1-c10 ;
  do i = 1 to 10 ;
    if countc(scan(formula, i, delims),'X') &amp;gt; 0 then ccc_[i] = scan(formula, i, delims) ;
  end ;
  drop delims i ;
run ;

Data Want;
  infile datalines dsd ;
  input C1 $3. C2 $3. C3 $3. ;
  datalines ;
X1 X2 X4
X1 X2 X3
;
Run ;

/**** My solution ***/

* Set number of array elements;
data _null_;
  set available;
  array elements $ c:;
  call symputx('arrdim',dim(elements));
run;
%put &amp;amp;=arrdim;

data result (drop=c:);
  set available;
  array elements $ c:;
  array out $ O1-O%eval(&amp;amp;arrdim);

  * left align elements - to solve bug in input creation;
  do i = 1 to dim(elements);
    elements{i} = left(elements{i});
  end;

  call sortc (of elements{*});
  j = 0;
  do i = 1 to dim(elements);
    if elements{i} ne '' then do;
      if i = 1 then do;
        j = j + 1;
        out{j} = elements{i};
      end;
      else if elements{i} ne elements{i-1} then do;
        j = j + 1;
        out{j} = elements{i};
      end;
    end;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 04 Sep 2022 08:32:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Scan-with-Delimiters-without-getting-blanks-or-duplicates/m-p/831706#M328703</guid>
      <dc:creator>ErikLund_Jensen</dc:creator>
      <dc:date>2022-09-04T08:32:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to Scan with Delimiters, without getting blanks or duplicates in the output</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Scan-with-Delimiters-without-getting-blanks-or-duplicates/m-p/831708#M328704</link>
      <description>&lt;P&gt;If you have Y1 or Z2 ...........&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;Data Have ;
  infile datalines dsd ;
  input formula : $30. ;
  datalines ;
X1 / X2 + X4
(X1 + X2) / (X3 - X1) * 2
;
Run ;

data temp;
 set have;
 id+1;
 pid=prxparse('/[a-z]\d+/i');
 start=1;end=length(formula);
 call prxnext(pid,start,end,formula,p,l);
 do while(p&amp;gt;0);
  temp=substr(formula,p,l);
  output;
  call prxnext(pid,start,end,formula,p,l);
 end;
keep id temp;
run;
proc sort data=temp nodupkey;by id temp;run;
proc transpose data=temp out=want(drop=_:) prefix=C;
by id;
var temp;
run;&lt;/PRE&gt;</description>
      <pubDate>Sun, 04 Sep 2022 10:35:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Scan-with-Delimiters-without-getting-blanks-or-duplicates/m-p/831708#M328704</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2022-09-04T10:35:25Z</dc:date>
    </item>
  </channel>
</rss>

