<?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: Calculating numeric value from CSV table with alphanumeric values in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Calculating-numeric-value-from-CSV-table-with-alphanumeric/m-p/191886#M14650</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hey,&lt;/P&gt;&lt;P&gt;Thank you for this. The data in the SAS column is an output that i received from an online source.&lt;/P&gt;&lt;P&gt;The 2009,2010,2011 can be of any length i.e.&lt;/P&gt;&lt;P&gt;data have;&lt;/P&gt;&lt;P&gt;&amp;nbsp; pvalue="2007,2008,2009,2010,2011,2012"; output;&lt;/P&gt;&lt;P&gt;&amp;nbsp; pvalue="2009,2010xyz"; output;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;The "Full" can be character/ word i.e. xyz, abc. The output table which you produced is perfect.&lt;/P&gt;&lt;P&gt;thanks once again&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 21 Oct 2014 09:33:03 GMT</pubDate>
    <dc:creator>sebster24</dc:creator>
    <dc:date>2014-10-21T09:33:03Z</dc:date>
    <item>
      <title>Calculating numeric value from CSV table with alphanumeric values</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Calculating-numeric-value-from-CSV-table-with-alphanumeric/m-p/191884#M14648</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello everyone,&lt;/P&gt;&lt;P&gt;I have currently a huge list of comma separated values in one column and i need to add +1 to the comma separated numeric values. The column contains alphanumeric characters.&lt;/P&gt;&lt;P&gt;I have tried and compiled this macro which does the following execution;&lt;/P&gt;&lt;P&gt;It looks at the comma separated alpha-numeric value in the cell under column "Pvalue", splits the values and then adds 1 to the numeric values, and then makes them a comma seperated list within the cell again.&lt;/P&gt;&lt;P&gt;So,&lt;/P&gt;&lt;P&gt;(pvalue)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (results)&lt;/P&gt;&lt;P&gt;2009,2010,2011&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ----&amp;gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2010, 2011,2012&lt;/P&gt;&lt;P&gt;2009,2010Full&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ----&amp;gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2010, 2011Full&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;CODE below;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/* DATA TABLE */&lt;/P&gt;&lt;P&gt;data&amp;nbsp; table1;&lt;BR /&gt; infile datalines delimiter = '_';&lt;BR /&gt; input SrNo $1. Pvalue $20.;&lt;BR /&gt; datalines;&lt;BR /&gt;1_2009,2010,2011&lt;BR /&gt;2_2009,2010Full&lt;/P&gt;&lt;P&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/* COMPILATION MACRO */&lt;/P&gt;&lt;P&gt;%macro adjustGenerationList(strg=);&lt;BR /&gt; %let newstr=%sysfunc(cat(&amp;amp;str,yy));&lt;BR /&gt; %let returnVal=;&lt;BR /&gt; %let stri=&amp;amp;strg.;&lt;BR /&gt; %put received: &amp;amp;newstr.;&lt;BR /&gt; %let cnt=1;&lt;BR /&gt; %let returnVal=&amp;amp;stri.;&lt;/P&gt;&lt;P&gt; %do %while(%qscan(%quote(&amp;amp;strg.),&amp;amp;cnt.,%STR(,)) ne %str());&lt;BR /&gt;&amp;nbsp; %let gen = %sysfunc(strip(%qscan(%quote(&amp;amp;strg.),&amp;amp;cnt.,%STR(,))));&lt;BR /&gt;&amp;nbsp; %put splitted gen: &amp;amp;gen;&lt;BR /&gt;&amp;nbsp; %let gen1up=%eval(&amp;amp;gen+1);&lt;BR /&gt;&amp;nbsp; %put gen after up1: &amp;amp;gen1up;&lt;/P&gt;&lt;P&gt;&amp;nbsp; %if &amp;amp;cnt = 1 %then&lt;BR /&gt;&amp;nbsp;&amp;nbsp; %let returnVal=&amp;amp;gen1up;&lt;BR /&gt;&amp;nbsp; %else %let returnVal=%sysfunc(cat(%quote(&amp;amp;returnVal),%str(,),&amp;amp;gen1up));&lt;BR /&gt;&amp;nbsp; %put returnval: &amp;amp;returnVal.;&lt;BR /&gt;&amp;nbsp; %let cnt=&amp;amp;cnt+1;&lt;BR /&gt; %end;&lt;/P&gt;&lt;P&gt; &amp;amp;returnVal.&lt;BR /&gt;%mend adjustGenerationList;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/* PROBLEM IN EXECUTION */&lt;/P&gt;&lt;P&gt;proc Sql;&lt;BR /&gt; select&amp;nbsp; *,"%adjustGenerationList(str="||%str(pvalue)||")" as results&lt;BR /&gt;&amp;nbsp; from table1&lt;BR /&gt; ;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;THE PROBLEM:&lt;/P&gt;&lt;P&gt;I am unable to run the code if the &lt;STRONG&gt;column name&lt;/STRONG&gt; is specified i.e.(as above) Rather if I specify the year as below then it works, but places the value in different columns, rather than concatenated in a single column for each row.&lt;/P&gt;&lt;P&gt;/* SOMEWHAT FUNCTIONAL */&lt;/P&gt;&lt;P&gt;proc Sql;&lt;/P&gt;&lt;P&gt;create table work.trialtable as&lt;/P&gt;&lt;P&gt;select&amp;nbsp; *,%adjustGenerationList(strg=%str(2009,2010,2011)) as xx&lt;/P&gt;&lt;P&gt;from t1&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Please help me.&lt;/P&gt;&lt;P&gt;All help would be appreciated.&lt;/P&gt;&lt;P&gt;thank you.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 21 Oct 2014 08:53:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Calculating-numeric-value-from-CSV-table-with-alphanumeric/m-p/191884#M14648</guid>
      <dc:creator>sebster24</dc:creator>
      <dc:date>2014-10-21T08:53:29Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating numeric value from CSV table with alphanumeric values</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Calculating-numeric-value-from-CSV-table-with-alphanumeric/m-p/191885#M14649</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Well couple of questions.&amp;nbsp; Firstly, why do you have the data in a SAS column separated by a comma, this doesn't make sense.&amp;nbsp; CSV is a file transport format which is read into variables in a SAS dataset.&lt;/P&gt;&lt;P&gt;Secondly the data above does not look like a CSV file.&amp;nbsp; The last row "2009,2010Full" is missing a column, which would be indicated by a comma after the word full, or prior to the word full. &lt;/P&gt;&lt;P&gt;So stage one, identify your data, does Full appear in col2 or in col3, if so then put the comma in.&amp;nbsp; Also separate your data out into columns so you can work with it, if you need CSV output then deal with putting it out to a file later.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data have;&lt;BR /&gt;&amp;nbsp; pvalue="2009,2010,2011"; output;&lt;BR /&gt;&amp;nbsp; pvalue="2009,2010,Full"; output;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;data want (drop=i);&lt;BR /&gt;&amp;nbsp; set have;&lt;BR /&gt;&amp;nbsp; length new_pvalue $200.;&lt;BR /&gt;&amp;nbsp; do i=1 to 3;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if anyalpha(scan(pvalue,i,',')) &amp;gt; 0 then new_pvalue=catx(',',strip(new_pvalue),strip(scan(pvalue,i,',')));&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; else new_pvalue=catx(',',strip(new_pvalue),strip(put(input(scan(pvalue,i,','),best.)+1,best.)));&lt;BR /&gt;&amp;nbsp; end;&lt;BR /&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 21 Oct 2014 09:11:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Calculating-numeric-value-from-CSV-table-with-alphanumeric/m-p/191885#M14649</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2014-10-21T09:11:11Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating numeric value from CSV table with alphanumeric values</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Calculating-numeric-value-from-CSV-table-with-alphanumeric/m-p/191886#M14650</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hey,&lt;/P&gt;&lt;P&gt;Thank you for this. The data in the SAS column is an output that i received from an online source.&lt;/P&gt;&lt;P&gt;The 2009,2010,2011 can be of any length i.e.&lt;/P&gt;&lt;P&gt;data have;&lt;/P&gt;&lt;P&gt;&amp;nbsp; pvalue="2007,2008,2009,2010,2011,2012"; output;&lt;/P&gt;&lt;P&gt;&amp;nbsp; pvalue="2009,2010xyz"; output;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;The "Full" can be character/ word i.e. xyz, abc. The output table which you produced is perfect.&lt;/P&gt;&lt;P&gt;thanks once again&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 21 Oct 2014 09:33:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Calculating-numeric-value-from-CSV-table-with-alphanumeric/m-p/191886#M14650</guid>
      <dc:creator>sebster24</dc:creator>
      <dc:date>2014-10-21T09:33:03Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating numeric value from CSV table with alphanumeric values</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Calculating-numeric-value-from-CSV-table-with-alphanumeric/m-p/191887#M14651</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Something like:&lt;/P&gt;&lt;P&gt;data have;&lt;BR /&gt;&amp;nbsp; pvalue="2007,2008,2009,2010,2011,2012"; output;&lt;BR /&gt;&amp;nbsp; pvalue="2009,2010xyz"; output;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;data want;&lt;BR /&gt;&amp;nbsp; set have;&lt;BR /&gt;&amp;nbsp; length new_pvalue $200.;&lt;BR /&gt;&amp;nbsp; i=1;&lt;BR /&gt;&amp;nbsp; do until (scan(pvalue,i,',')="");&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if anyalpha(scan(pvalue,i,','))=0 then do;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; new_pvalue=catx(',',strip(new_pvalue),strip(put(input(scan(pvalue,i,','),best.)+1,best.)));&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; else do;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; new_pvalue=catx(',',strip(new_pvalue),strip(put(input(substr(scan(pvalue,i,','),1,4),best.)+1,best.)),substr(scan(pvalue,i,','),5));&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; i=i+1;&lt;BR /&gt;&amp;nbsp; end;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Note that if you don't want the comma before the text, then take the last bit out of the else do catx and just concatenate it.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 21 Oct 2014 09:55:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Calculating-numeric-value-from-CSV-table-with-alphanumeric/m-p/191887#M14651</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2014-10-21T09:55:48Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating numeric value from CSV table with alphanumeric values</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Calculating-numeric-value-from-CSV-table-with-alphanumeric/m-p/191888#M14652</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Genius!! Thank you. This worked like a charm.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 21 Oct 2014 12:45:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Calculating-numeric-value-from-CSV-table-with-alphanumeric/m-p/191888#M14652</guid>
      <dc:creator>sebster24</dc:creator>
      <dc:date>2014-10-21T12:45:14Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating numeric value from CSV table with alphanumeric values</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Calculating-numeric-value-from-CSV-table-with-alphanumeric/m-p/191889#M14653</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Did you also need to add an blank before 'Full' ?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;data&amp;nbsp; table1;
infile datalines delimiter = '_';
input SrNo : $1. Pvalue $20.;
datalines;
1_2009,2010,2011
2_2009,2010Full
;
run;
data want;
 set table1;
new=prxchange('s/(,|\d(?=[a-zA-Z]))/$1 /o',-1,Pvalue);
run;

&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Xia Keshan&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 21 Oct 2014 13:48:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Calculating-numeric-value-from-CSV-table-with-alphanumeric/m-p/191889#M14653</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2014-10-21T13:48:08Z</dc:date>
    </item>
  </channel>
</rss>

