<?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: ascii value loop in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/ascii-value-loop/m-p/357227#M274231</link>
    <description>&lt;P&gt;Show your code, and post example data in a data step. Your intentions are very unclear, at least to me.&lt;/P&gt;</description>
    <pubDate>Tue, 09 May 2017 15:59:52 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2017-05-09T15:59:52Z</dc:date>
    <item>
      <title>ascii value loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/ascii-value-loop/m-p/357213#M274225</link>
      <description>&lt;P&gt;okay, so i have a field with names in it called name.&amp;nbsp; i am trying to parallel a process.&amp;nbsp; i am relatively new to sas as well so here is what i need to do...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;i need to get the ascii values of the first 30 letters (ONLY because it can be more) of the name, sum them and update a field a_name with a concatenation of that and the fields record number.&amp;nbsp; so, like this...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;id&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; name&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; a_name&lt;/P&gt;&lt;P&gt;101&amp;nbsp; abcd&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 101-394&lt;/P&gt;&lt;P&gt;102&amp;nbsp; efgh&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 102-410&lt;/P&gt;&lt;P&gt;103&amp;nbsp; ijkl&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 103-426 ...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;you get the idea.&amp;nbsp; i am piecing it together but help would be appreciated.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 09 May 2017 15:27:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/ascii-value-loop/m-p/357213#M274225</guid>
      <dc:creator>me55</dc:creator>
      <dc:date>2017-05-09T15:27:43Z</dc:date>
    </item>
    <item>
      <title>Re: ascii value loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/ascii-value-loop/m-p/357215#M274226</link>
      <description>&lt;P&gt;This works for your example data:&lt;/P&gt;
&lt;PRE&gt;data have;
infile datalines truncover;
informat id $5. name $30.;
input id name;
datalines;
101  abcd     
102  efgh     
103  ijkl     
;
run;

data want;
   set have;
   do i= 1 to length(name);
      count= sum(count,rank(substr(name,i,1)));
   end;
   length a_name $ 12;
   a_name=catx('-',id,count);
   drop i count;
run;&lt;/PRE&gt;
&lt;P&gt;HOWEVER there may be a few things to consider. Does your "name" variable include trailing blanks as part of the value?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also the lengths I assigned to id and a_name a guesses. You'll have to provide better based on your actual values.&lt;/P&gt;</description>
      <pubDate>Tue, 09 May 2017 15:35:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/ascii-value-loop/m-p/357215#M274226</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-05-09T15:35:31Z</dc:date>
    </item>
    <item>
      <title>Re: ascii value loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/ascii-value-loop/m-p/357216#M274227</link>
      <description>What do you mean by sum them, it's a char variable. &lt;BR /&gt;And record no, is that an exact no or an aggregation as well.&lt;BR /&gt;Perhaps a "have" data set would clarify.</description>
      <pubDate>Tue, 09 May 2017 15:38:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/ascii-value-loop/m-p/357216#M274227</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2017-05-09T15:38:02Z</dc:date>
    </item>
    <item>
      <title>Re: ascii value loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/ascii-value-loop/m-p/357218#M274228</link>
      <description>&lt;P&gt;this is an ~80,000 line table.&amp;nbsp; i believe i have id set at 6 and then name can be up to 50.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 09 May 2017 15:41:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/ascii-value-loop/m-p/357218#M274228</guid>
      <dc:creator>me55</dc:creator>
      <dc:date>2017-05-09T15:41:43Z</dc:date>
    </item>
    <item>
      <title>Re: ascii value loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/ascii-value-loop/m-p/357221#M274229</link>
      <description>&lt;P&gt;id is an auto-numbered field that simply counts up to the last line in the table and that is record number...and as i said, it needs to find the ASCII VALUE of the characters and sum them.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 09 May 2017 15:43:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/ascii-value-loop/m-p/357221#M274229</guid>
      <dc:creator>me55</dc:creator>
      <dc:date>2017-05-09T15:43:47Z</dc:date>
    </item>
    <item>
      <title>Re: ascii value loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/ascii-value-loop/m-p/357225#M274230</link>
      <description>&lt;P&gt;yeah, my first attempt that did not work.&amp;nbsp; i am sure it is the datalines part.&amp;nbsp; so this needs to run for every value in a table that has 80k values in it.&amp;nbsp; i cannot write out that many datalines.&amp;nbsp; also, the name are business names so there could be values in them however i have removed all trailing spaces via trim or something...&lt;/P&gt;</description>
      <pubDate>Tue, 09 May 2017 15:53:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/ascii-value-loop/m-p/357225#M274230</guid>
      <dc:creator>me55</dc:creator>
      <dc:date>2017-05-09T15:53:54Z</dc:date>
    </item>
    <item>
      <title>Re: ascii value loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/ascii-value-loop/m-p/357227#M274231</link>
      <description>&lt;P&gt;Show your code, and post example data in a data step. Your intentions are very unclear, at least to me.&lt;/P&gt;</description>
      <pubDate>Tue, 09 May 2017 15:59:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/ascii-value-loop/m-p/357227#M274231</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-05-09T15:59:52Z</dc:date>
    </item>
    <item>
      <title>Re: ascii value loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/ascii-value-loop/m-p/357228#M274232</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/113010"&gt;@me55&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;yeah, my first attempt that did not work.&amp;nbsp; i am sure it is the datalines part.&amp;nbsp; so this needs to run for every value in a table that has 80k values in it.&amp;nbsp; i cannot write out that many datalines.&amp;nbsp; also, the name are business names so there could be values in them however i have removed all trailing spaces via trim or something...&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;YOU do not need the datalines. I did that to provide a workable SAS data set. You should only need the Data Want step if you already have a SAS data set. If you don't have a SAS data set then import or use a data step to read the text file.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The length I set for a_name as I said was a guess. If your ID was 10 characters and you have up to 50 characters in name then you need to make a_name at least 10(length of ID) +1(for the dash) + something long enough to hold the sum of 50 ASCII codes. Assuming (big dange but..) an average ASCII value of about 100 then 50 characters should have a sum near 50*100 = 5000 and fit into 4 characters. BUT I would probably push that upe to 6 or so for a total length of 10+1+6 = 17. Or ignore that and let CATX set the length to possibly&amp;nbsp;some much larger value.&lt;/P&gt;</description>
      <pubDate>Tue, 09 May 2017 16:03:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/ascii-value-loop/m-p/357228#M274232</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-05-09T16:03:31Z</dc:date>
    </item>
    <item>
      <title>Re: ascii value loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/ascii-value-loop/m-p/357230#M274233</link>
      <description>&lt;P&gt;The result depends on whether you include the spaces at the end of the names. Looks like you do not.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  length id 8 name $50 want $40 ;
  input id name want ;
cards;
101  abcd 101-394
102  efgh 102-410
103  ijkl 103-426
104  ThisNameHasMoreThanThirtyCharactersInIt ?
;

data want ;
  set have ;
  do _n_=1 to min(30,length(name));
    sum_ascii=sum(sum_ascii,rank(char(name,_n_)));
  end;
  do _n_=1 to 30;
    sum_ascii2=sum(sum_ascii2,rank(char(name,_n_)));
  end;
  do _n_=1 to length(name);
    sum_ascii3=sum(sum_ascii3,rank(char(name,_n_)));
  end;

  a_name = catx('-',id,put(sum_ascii,32.));
run;
proc print; run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/8783iDDC25647A6C30ADF/image-size/original?v=1.0&amp;amp;px=-1" border="0" alt="Capture.PNG" title="Capture.PNG" /&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 09 May 2017 16:09:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/ascii-value-loop/m-p/357230#M274233</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-05-09T16:09:57Z</dc:date>
    </item>
    <item>
      <title>Re: ascii value loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/ascii-value-loop/m-p/357232#M274234</link>
      <description>&lt;P&gt;i need it to cut off at 30.&amp;nbsp; i removed the data lines...i assumed that was not needed but i am getting another error.&amp;nbsp; so the table i am trying to update in is table_a so...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data table_a;&lt;BR /&gt;infile table_a;&lt;BR /&gt;informat id $6. name $30.&lt;BR /&gt;input id name;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;data table_a;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;set table_a;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;do i=1 to length(name);&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; count=sum(count,rank(substr(name,i,1)));&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;end;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; length name $ 12;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; a_name=catx('-',id,count);&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;drop iaap count;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;basically i want to update a field in the same table.&amp;nbsp; so i put want=have in your example and it seems to be having an issue there...&lt;/P&gt;</description>
      <pubDate>Tue, 09 May 2017 16:11:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/ascii-value-loop/m-p/357232#M274234</guid>
      <dc:creator>me55</dc:creator>
      <dc:date>2017-05-09T16:11:15Z</dc:date>
    </item>
    <item>
      <title>Re: ascii value loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/ascii-value-loop/m-p/357244#M274235</link>
      <description>&lt;P&gt;Your first data step does not make much sense. &amp;nbsp;If do not have a dataset yet then ask a new question about how to create a dataset.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So let's just assume that you already have a dataset named &lt;STRONG&gt;TABLE_A&lt;/STRONG&gt; with two variables named &lt;STRONG&gt;ID&lt;/STRONG&gt; and &lt;STRONG&gt;NAME&lt;/STRONG&gt; and want to create a new variable named &lt;STRONG&gt;A_NAME&lt;/STRONG&gt;. &amp;nbsp;&lt;EM&gt;If you already have a variable named A_NAME then remove the LENGTH statement.&lt;/EM&gt; &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also let's make the new dataset have a different name than the input dataset so that when it fails we haven't lost the&amp;nbsp;input dataset.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data new_table_a;
    set table_a;
    do i=1 to min(length(name),30);    
      count=sum(count,rank(char(name,i)));
    end;
    length a_name $12;
    a_name=catx('-',id,count);
    drop i count;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 09 May 2017 16:56:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/ascii-value-loop/m-p/357244#M274235</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-05-09T16:56:28Z</dc:date>
    </item>
    <item>
      <title>Re: ascii value loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/ascii-value-loop/m-p/357248#M274236</link>
      <description>&lt;P&gt;This structure:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Data existingdataset;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; set existingdataset;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Does not&lt;/STRONG&gt; "update" it completely overwrites the existing data set and hence is a dangerous construct.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Start with sending output to a new data set. If you only want to test something you can restrict the number of observations processed by using the OBS option.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you a FILENAME statement referencing you external file as table_a? That is what your infile would expect.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You say "so i put want=have in your example and it seems to be having an issue there..." What exactly is the issue? I expect at least&lt;/P&gt;
&lt;P&gt;a warning along the lines of&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; WARNING: Length of character variable name has already been set.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Use the LENGTH statement as the very first statement in the DATA STEP to declare the&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; length of a character variable.&lt;/P&gt;
&lt;P&gt;because you have: Length name $ 12; instead of Length A_name.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that&lt;/P&gt;
&lt;P&gt;do i= 1 to length(name);&lt;/P&gt;
&lt;P&gt;should change to&lt;/P&gt;
&lt;P&gt;do i= 1 to&amp;nbsp; min(30,length(name));&lt;/P&gt;
&lt;P&gt;to limit to the first 30 characters.&lt;/P&gt;</description>
      <pubDate>Tue, 09 May 2017 17:14:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/ascii-value-loop/m-p/357248#M274236</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-05-09T17:14:38Z</dc:date>
    </item>
    <item>
      <title>Re: ascii value loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/ascii-value-loop/m-p/357258#M274237</link>
      <description>&lt;P&gt;having a bit of a day here...okay so i need this data back in the original table.&amp;nbsp; this is the last step before i build a final report and it is going to use most of the data in the table...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;also, keep in mind i am very new to sas.&amp;nbsp; while i have deep knowledge of sql, the data step stuff, i am learning as i am going here.&amp;nbsp; personally i would rather do it in proc sql but i do need to learn sas and data steps so...i am still trying to fully understand these data steps but i do need the data back in the original table.&amp;nbsp; the only other way is i need all of the data moved from the current table to a new table with the new data.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 09 May 2017 17:37:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/ascii-value-loop/m-p/357258#M274237</guid>
      <dc:creator>me55</dc:creator>
      <dc:date>2017-05-09T17:37:37Z</dc:date>
    </item>
    <item>
      <title>Re: ascii value loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/ascii-value-loop/m-p/357269#M274238</link>
      <description>&lt;P&gt;Database system have their own view of how to process things. Normally because they are geared around gathering and storing data. &amp;nbsp;Usually making a new table (dataset) or database (library) is complex, time comsuming and left to specialist. &amp;nbsp;So in that type of system it might make sense to think in terms on updating variables (fields, columns) in an existing dataset (table, object). &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SAS is more designed for manipulating and reporting on data. &amp;nbsp;So you take your inputs manipulate them to calculate the values you need and produce your report. &amp;nbsp;You can save datasets (tables) easily and there is not much advantage to be gained from have pre-built datasets that you update in place.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In SAS if you have a current program that makes a report from table XXX it is trivial to update the program to report from table YYY instead (as long as it has the data you need). &amp;nbsp;You can even use macro variables so that the actual code doesn't change just the value of the macro variable that contains the dataset name that the program will use.&lt;/P&gt;</description>
      <pubDate>Tue, 09 May 2017 18:00:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/ascii-value-loop/m-p/357269#M274238</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-05-09T18:00:56Z</dc:date>
    </item>
    <item>
      <title>Re: ascii value loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/ascii-value-loop/m-p/357315#M274239</link>
      <description>although proc sql could mimic the design that might be familiar in database management systems ( ALTER table, adding new column A_NAME, then UPDATE deriving the A_NAME values). This is not the most efficient. &lt;BR /&gt;Better would be to test your derivation of A_NAME on small subsets of the data (where creating a new data set is quick and cheap) using the ideas recommended by others. &lt;BR /&gt;Once a suitable derivation is discovered, I would recommend two implementations: Create a VIEW rather than table, to be used if the value of A_NAME is seldom required; For the other implementation - get the A_NAME column derived when the original data are loaded.&lt;BR /&gt;  &lt;BR /&gt;Hope this helps you find the solution that works best for you.&lt;BR /&gt;peterC</description>
      <pubDate>Tue, 09 May 2017 21:38:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/ascii-value-loop/m-p/357315#M274239</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2017-05-09T21:38:39Z</dc:date>
    </item>
  </channel>
</rss>

