<?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: Handling dotted decimal strings. in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Handling-dotted-decimal-strings/m-p/13022#M1490</link>
    <description>You can combine the parts but then you have to have leading zeros or blanks and that gets you right back where you started.&lt;BR /&gt;
&lt;BR /&gt;
"P:" is called a "SAS Variable Lists".  There are a number of ways to specify an SVL including the nameroot followed by the colon.  The SVL is very powerful.  Look in the docuemention for a complete and detailed description.  You can use the SVL in data steps and most procs.  It is interesting to me that you can use something like  P: or even _ALL_ in a DEFINE statement in PROC REPORT but you can NOT use a list of variables like "p1 p2 p3".&lt;BR /&gt;
&lt;BR /&gt;
An array in SAS only exist in a data step.  It is a fancy way to refer to a list of variables with in INDEX.  A subtle difference from other programming languages but important.</description>
    <pubDate>Fri, 30 Apr 2010 12:12:45 GMT</pubDate>
    <dc:creator>data_null__</dc:creator>
    <dc:date>2010-04-30T12:12:45Z</dc:date>
    <item>
      <title>Handling dotted decimal strings.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Handling-dotted-decimal-strings/m-p/13019#M1487</link>
      <description>I would like to create a macro that would create a sort variable for a dotted decimal string (&lt;I&gt;Chap:&lt;/I&gt; 1.2.3.4 or &lt;I&gt;IP:&lt;/I&gt; 192.168.1.101) so that, for example, 1.10.1 would appear after 1.2.1 .&lt;BR /&gt;
&lt;BR /&gt;
I was unable to find anything similar in the forums.&lt;BR /&gt;
&lt;BR /&gt;
I can do this in Base SAS, but don't remember how to pass a data step variable into a macro.&lt;BR /&gt;
&lt;BR /&gt;
&lt;B&gt;I created the test data set with:&lt;/B&gt;&lt;BR /&gt;
&lt;BR /&gt;
data test ;&lt;BR /&gt;
   input chapter $ ;&lt;BR /&gt;
cards;&lt;BR /&gt;
1.2.2.5&lt;BR /&gt;
1.2.10.5&lt;BR /&gt;
2.10&lt;BR /&gt;
1.35&lt;BR /&gt;
1.2.5&lt;BR /&gt;
2.587&lt;BR /&gt;
2.3.9.8&lt;BR /&gt;
run ;&lt;BR /&gt;
&lt;BR /&gt;
&lt;B&gt;I created the data step version as:&lt;/B&gt;&lt;BR /&gt;
&lt;BR /&gt;
data test1 ;&lt;BR /&gt;
	set test ;&lt;BR /&gt;
	array part{5} $3 ;&lt;BR /&gt;
	length chapters $19 ;&lt;BR /&gt;
	do i= 1 to countc(chapter,".")+1 ;&lt;BR /&gt;
  		part(i)=scan(chapter,i);&lt;BR /&gt;
 		part(i)=translate(right(part(i)),"0"," ");&lt;BR /&gt;
		chapters=trim(chapters)||"."||part(i);&lt;BR /&gt;
		end;&lt;BR /&gt;
	chapters=substr(chapters,3);&lt;BR /&gt;
	run ;&lt;BR /&gt;
&lt;BR /&gt;
(the output gives a clearer idea of where I'm heading with this)&lt;BR /&gt;
&lt;BR /&gt;
&lt;B&gt;I created a macro that almost does what I'm looking for:&lt;/B&gt;&lt;BR /&gt;
&lt;BR /&gt;
%macro multidec(string);&lt;BR /&gt;
	%local part sect padc ;&lt;BR /&gt;
	%let part=1 ;&lt;BR /&gt;
	%let sect = %scan(&amp;amp;string, ∂) ;&lt;BR /&gt;
	%let padc=00 ;&lt;BR /&gt;
	%let mult= ;&lt;BR /&gt;
	%do %while(§ ne );&lt;BR /&gt;
 		%let sect=%substr(&amp;amp;padc§,%length(§)) ;&lt;BR /&gt;
		%let mult=&amp;amp;mult..§ ;&lt;BR /&gt;
		%let part=%eval(∂ + 1);&lt;BR /&gt;
		%let sect=%scan(&amp;amp;string, ∂) ;&lt;BR /&gt;
		%end;&lt;BR /&gt;
	%let mult=%substr(&amp;amp;mult,2) ;&lt;BR /&gt;
	%put &amp;amp;mult ;&lt;BR /&gt;
	%mend ;&lt;BR /&gt;
%multidec(1.2.3.4) ;&lt;BR /&gt;
&lt;BR /&gt;
Where I hang up is passing the value of chapter (1.2.3.4) into a macro. I'd like to pass in variable name from a dataset as well as the name of the new variable to be created, something like %multidec(chapter,chapters).&lt;BR /&gt;
&lt;BR /&gt;
Any suggestions you'd care to offer would be welcome. Especially if someone has already done this ...</description>
      <pubDate>Thu, 29 Apr 2010 20:36:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Handling-dotted-decimal-strings/m-p/13019#M1487</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2010-04-29T20:36:35Z</dc:date>
    </item>
    <item>
      <title>Re: Handling dotted decimal strings.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Handling-dotted-decimal-strings/m-p/13020#M1488</link>
      <description>I have done this from time to time.  I find it is easier to create sort variable&lt;B&gt;S&lt;/B&gt; one for each dot so to speak.  You sort by these variables and display the original.&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
data test;&lt;BR /&gt;
   input chapter $;&lt;BR /&gt;
   array s[4];&lt;BR /&gt;
   length w $32;&lt;BR /&gt;
   drop w;&lt;BR /&gt;
   do _n_ = 1 to dim(s);&lt;BR /&gt;
      w = scan(chapter,_n_);&lt;BR /&gt;
      if missing(w) then leave;&lt;BR /&gt;
      s[_n_] = input(w,comma32.);&lt;BR /&gt;
      end;&lt;BR /&gt;
   cards;&lt;BR /&gt;
1.2.2.5&lt;BR /&gt;
1.2.10.5&lt;BR /&gt;
2.10&lt;BR /&gt;
1.35&lt;BR /&gt;
1.2.5&lt;BR /&gt;
2.587&lt;BR /&gt;
2.3.9.8&lt;BR /&gt;
   ;;;;&lt;BR /&gt;
   run;&lt;BR /&gt;
proc sort; &lt;BR /&gt;
   by s:;&lt;BR /&gt;
   run;&lt;BR /&gt;
proc print;&lt;BR /&gt;
   run;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
Obs    chapter     s1     s2    s3    s4&lt;BR /&gt;
&lt;BR /&gt;
 1     1.2.2.5      1      2     2     5&lt;BR /&gt;
 2     1.2.5        1      2     5     .&lt;BR /&gt;
 3     1.2.10.5     1      2    10     5&lt;BR /&gt;
 4     1.35         1     35     .     .&lt;BR /&gt;
 5     2.3.9.8      2      3     9     8&lt;BR /&gt;
 6     2.10         2     10     .     .&lt;BR /&gt;
 7     2.587        2    587     .     .&lt;BR /&gt;
[/pre]</description>
      <pubDate>Thu, 29 Apr 2010 21:12:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Handling-dotted-decimal-strings/m-p/13020#M1488</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2010-04-29T21:12:51Z</dc:date>
    </item>
    <item>
      <title>Re: Handling dotted decimal strings.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Handling-dotted-decimal-strings/m-p/13021#M1489</link>
      <description>Thanks _null_.&lt;BR /&gt;
&lt;BR /&gt;
I was hoping to collapse the 'part's but thank you.&lt;BR /&gt;
&lt;BR /&gt;
I also learned something new from your example that was quite valuable.&lt;BR /&gt;
&lt;BR /&gt;
I did not know I could sort with a by 's:' which apparently uses all the components of the array 's'. Thanks for that.</description>
      <pubDate>Fri, 30 Apr 2010 00:53:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Handling-dotted-decimal-strings/m-p/13021#M1489</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2010-04-30T00:53:11Z</dc:date>
    </item>
    <item>
      <title>Re: Handling dotted decimal strings.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Handling-dotted-decimal-strings/m-p/13022#M1490</link>
      <description>You can combine the parts but then you have to have leading zeros or blanks and that gets you right back where you started.&lt;BR /&gt;
&lt;BR /&gt;
"P:" is called a "SAS Variable Lists".  There are a number of ways to specify an SVL including the nameroot followed by the colon.  The SVL is very powerful.  Look in the docuemention for a complete and detailed description.  You can use the SVL in data steps and most procs.  It is interesting to me that you can use something like  P: or even _ALL_ in a DEFINE statement in PROC REPORT but you can NOT use a list of variables like "p1 p2 p3".&lt;BR /&gt;
&lt;BR /&gt;
An array in SAS only exist in a data step.  It is a fancy way to refer to a list of variables with in INDEX.  A subtle difference from other programming languages but important.</description>
      <pubDate>Fri, 30 Apr 2010 12:12:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Handling-dotted-decimal-strings/m-p/13022#M1490</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2010-04-30T12:12:45Z</dc:date>
    </item>
  </channel>
</rss>

