<?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 Printing a range of values in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Printing-a-range-of-values/m-p/19920#M4079</link>
    <description>Hi,&lt;BR /&gt;
&lt;BR /&gt;
I am trying to figure something out, and the solution is probably very easy.  I have a listing of numbers that I would like to see printed as ranges.&lt;BR /&gt;
&lt;BR /&gt;
Before:&lt;BR /&gt;
200&lt;BR /&gt;
201&lt;BR /&gt;
202*&lt;BR /&gt;
203&lt;BR /&gt;
204*&lt;BR /&gt;
205&lt;BR /&gt;
206&lt;BR /&gt;
&lt;BR /&gt;
After:&lt;BR /&gt;
200 - 201, 203, 205-206&lt;BR /&gt;
&lt;BR /&gt;
The numbers with asterisk will be printed separately.  I have no clue where to start.&lt;BR /&gt;
Thanks!</description>
    <pubDate>Wed, 20 Oct 2010 17:45:22 GMT</pubDate>
    <dc:creator>deleted_user</dc:creator>
    <dc:date>2010-10-20T17:45:22Z</dc:date>
    <item>
      <title>Printing a range of values</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Printing-a-range-of-values/m-p/19920#M4079</link>
      <description>Hi,&lt;BR /&gt;
&lt;BR /&gt;
I am trying to figure something out, and the solution is probably very easy.  I have a listing of numbers that I would like to see printed as ranges.&lt;BR /&gt;
&lt;BR /&gt;
Before:&lt;BR /&gt;
200&lt;BR /&gt;
201&lt;BR /&gt;
202*&lt;BR /&gt;
203&lt;BR /&gt;
204*&lt;BR /&gt;
205&lt;BR /&gt;
206&lt;BR /&gt;
&lt;BR /&gt;
After:&lt;BR /&gt;
200 - 201, 203, 205-206&lt;BR /&gt;
&lt;BR /&gt;
The numbers with asterisk will be printed separately.  I have no clue where to start.&lt;BR /&gt;
Thanks!</description>
      <pubDate>Wed, 20 Oct 2010 17:45:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Printing-a-range-of-values/m-p/19920#M4079</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2010-10-20T17:45:22Z</dc:date>
    </item>
    <item>
      <title>Re: Printing a range of values</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Printing-a-range-of-values/m-p/19921#M4080</link>
      <description>Hi:&lt;BR /&gt;
  You say you want to see these numbers "printed" -- what do you mean by that? Are you running PROC PRINT, PROC REPORT, PROC TABULATE??? Are you running PROC SQL?? Are you using ODS and if so, what is your destination of interest??&lt;BR /&gt;
&lt;BR /&gt;
  You show a "before" and "after" but do not indicate whether there are any counts or other values underneath your variable values. What is the name of the variable that contains the numbers 200, 201, etc??? What you describe seems to be that you want the variable values (from BEFORE) to become column headers???? If that is the case, do keep in mind that SAS variable names cannot start with a number -- they can only start with a character or an underscore.&lt;BR /&gt;
&lt;BR /&gt;
  You could create a custom report, written to FILE PRINT, using PUT statements, but without more information about your data, what the data represents and where the final "printed" report is going (destination) and what else should be on the final report, it's hard to give a definitive answer.&lt;BR /&gt;
&lt;BR /&gt;
  Can you explain a bit more about this task and the intended usage for the report with the newly printed/rearranged rows???? &lt;BR /&gt;
          &lt;BR /&gt;
  cynthia</description>
      <pubDate>Wed, 20 Oct 2010 18:00:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Printing-a-range-of-values/m-p/19921#M4080</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2010-10-20T18:00:15Z</dc:date>
    </item>
    <item>
      <title>Re: Printing a range of values</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Printing-a-range-of-values/m-p/19922#M4081</link>
      <description>Sorry - the numbers are participant id numbers with the variable name IDNUM.  I would like to print just the values of the variable IDNUM to represent a specific event:  200-202, 204 all passed a test.  I need to create a report that shows these ranges, instead of each number individually.  &lt;BR /&gt;
&lt;BR /&gt;
Currently I'm using Base SAS and printing them using PROC PRINT.  However, I am totally open to trying PROC REPORT or PROC TABULATE.  I'm also open to using ODS.</description>
      <pubDate>Wed, 20 Oct 2010 19:04:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Printing-a-range-of-values/m-p/19922#M4081</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2010-10-20T19:04:03Z</dc:date>
    </item>
    <item>
      <title>Re: Printing a range of values</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Printing-a-range-of-values/m-p/19923#M4082</link>
      <description>Hello LisaB,&lt;BR /&gt;
&lt;BR /&gt;
This is my solution but I am not sure that this is what you need:.&lt;BR /&gt;
&lt;BR /&gt;
data a;&lt;BR /&gt;
  length id $4; &lt;BR /&gt;
  input id;&lt;BR /&gt;
datalines;&lt;BR /&gt;
200&lt;BR /&gt;
201&lt;BR /&gt;
202*&lt;BR /&gt;
203&lt;BR /&gt;
204*&lt;BR /&gt;
205&lt;BR /&gt;
206&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
/*  Creating group variable i */;&lt;BR /&gt;
data a1;&lt;BR /&gt;
  set a;&lt;BR /&gt;
  if SUBSTR(id,4,1) = "*" then i+1;&lt;BR /&gt;
  else output;&lt;BR /&gt;
run; &lt;BR /&gt;
/* Creating variable r for id ranges */;&lt;BR /&gt;
data a2;&lt;BR /&gt;
  length r1 $3 r $10;&lt;BR /&gt;
  retain r1;&lt;BR /&gt;
  set a1;&lt;BR /&gt;
  if first.i then r1=SUBSTR(id,1,3);&lt;BR /&gt;
  if first.i and last.i then do; r=r1; output; end;&lt;BR /&gt;
  if not first.i and last.i then do; r=r1||"-"||id; end;&lt;BR /&gt;
  by i;&lt;BR /&gt;
run; &lt;BR /&gt;
proc print data=a2;&lt;BR /&gt;
  var r;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
Sincerely,&lt;BR /&gt;
SPR</description>
      <pubDate>Wed, 20 Oct 2010 19:38:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Printing-a-range-of-values/m-p/19923#M4082</guid>
      <dc:creator>SPR</dc:creator>
      <dc:date>2010-10-20T19:38:38Z</dc:date>
    </item>
    <item>
      <title>Re: Printing a range of values</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Printing-a-range-of-values/m-p/19924#M4083</link>
      <description>Sorry, I forgot OUTPUT in the following line of the last data step:&lt;BR /&gt;
&lt;BR /&gt;
  if not first.i and last.i then do; r=r1||"-"||id; OUTPUT; end;&lt;BR /&gt;
&lt;BR /&gt;
SPR</description>
      <pubDate>Wed, 20 Oct 2010 19:46:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Printing-a-range-of-values/m-p/19924#M4083</guid>
      <dc:creator>SPR</dc:creator>
      <dc:date>2010-10-20T19:46:57Z</dc:date>
    </item>
    <item>
      <title>Re: Printing a range of values</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Printing-a-range-of-values/m-p/19925#M4084</link>
      <description>Hi.&lt;BR /&gt;
Suppose you are doing survival statistical analysis.and asterisk denoted the censored data, right?&lt;BR /&gt;
And also i do not think it is easy to do.Hope somebody gives a brief and directly resolution.&lt;BR /&gt;
It my rude code.&lt;BR /&gt;
[pre]&lt;BR /&gt;
data a;&lt;BR /&gt;
input id : $;&lt;BR /&gt;
datalines;&lt;BR /&gt;
200&lt;BR /&gt;
201&lt;BR /&gt;
202*&lt;BR /&gt;
203&lt;BR /&gt;
204*&lt;BR /&gt;
205&lt;BR /&gt;
206&lt;BR /&gt;
207&lt;BR /&gt;
208&lt;BR /&gt;
209*&lt;BR /&gt;
210&lt;BR /&gt;
211&lt;BR /&gt;
212&lt;BR /&gt;
213&lt;BR /&gt;
214&lt;BR /&gt;
215*&lt;BR /&gt;
216&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
/* Creating group variable i */&lt;BR /&gt;
data asterisk data;&lt;BR /&gt;
 set a;&lt;BR /&gt;
 retain i 1;&lt;BR /&gt;
 if findc(id,'*') then do;&lt;BR /&gt;
                           i+1;&lt;BR /&gt;
                           output asterisk;&lt;BR /&gt;
						   end;&lt;BR /&gt;
  else output data;&lt;BR /&gt;
run;&lt;BR /&gt;
data result;&lt;BR /&gt;
 set data;&lt;BR /&gt;
 by i;&lt;BR /&gt;
 length result $ 10 firstid $ 4;&lt;BR /&gt;
 retain result firstid;&lt;BR /&gt;
 if first.i and not last.i then  firstid=id;&lt;BR /&gt;
 else if not first.i and last.i then do;&lt;BR /&gt;
                                result=catx('-',firstid,id);&lt;BR /&gt;
								output;&lt;BR /&gt;
								end;&lt;BR /&gt;
 else if first.i and last.i then do;&lt;BR /&gt;
                            result=id;&lt;BR /&gt;
							output;&lt;BR /&gt;
							end;&lt;BR /&gt;
run;&lt;BR /&gt;
proc sql noprint;&lt;BR /&gt;
 select result&lt;BR /&gt;
  into :result separated by ','&lt;BR /&gt;
   from result;&lt;BR /&gt;
quit;&lt;BR /&gt;
%put the result is : &amp;amp;result; &lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Ksharp&lt;BR /&gt;
&lt;BR /&gt;
Message was edited by: Ksharp</description>
      <pubDate>Thu, 21 Oct 2010 07:38:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Printing-a-range-of-values/m-p/19925#M4084</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2010-10-21T07:38:08Z</dc:date>
    </item>
    <item>
      <title>Re: Printing a range of values</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Printing-a-range-of-values/m-p/19926#M4085</link>
      <description>Here is another way, writing to lst.&lt;BR /&gt;
[pre]&lt;BR /&gt;
   /*  test data */&lt;BR /&gt;
   data one;&lt;BR /&gt;
      input id : $ @@;&lt;BR /&gt;
   datalines;&lt;BR /&gt;
   200 201 202* 203 204* 205 206 207 208&lt;BR /&gt;
   209* 210 211 212 213 214 215* 216&lt;BR /&gt;
   ;&lt;BR /&gt;
   run;&lt;BR /&gt;
&lt;BR /&gt;
   /* this assumes that id^s are conjecutive */&lt;BR /&gt;
   data _null_;&lt;BR /&gt;
      length start finish range $20 comma $1;&lt;BR /&gt;
      retain start finish comma "";&lt;BR /&gt;
&lt;BR /&gt;
      set one end=end;&lt;BR /&gt;
&lt;BR /&gt;
      star = index(id,"*") &amp;gt; 0;&lt;BR /&gt;
      if star then do;&lt;BR /&gt;
         if missing(start) then return;&lt;BR /&gt;
         link outRange;&lt;BR /&gt;
         call missing(start, finish);&lt;BR /&gt;
      end; else do;&lt;BR /&gt;
         if missing(start) then start = id;&lt;BR /&gt;
         finish = id;&lt;BR /&gt;
      end;&lt;BR /&gt;
      if end and not missing(start) then link outRange;&lt;BR /&gt;
      return;&lt;BR /&gt;
&lt;BR /&gt;
      outRange:&lt;BR /&gt;
         file print;&lt;BR /&gt;
&lt;BR /&gt;
         len = lengthn(comma);&lt;BR /&gt;
         put comma $varying. len @;&lt;BR /&gt;
&lt;BR /&gt;
         range = ifc(start=finish, start, catx("-", start, finish));&lt;BR /&gt;
         len = lengthn(range);&lt;BR /&gt;
         put range $varying. len @;&lt;BR /&gt;
&lt;BR /&gt;
         comma = ",";&lt;BR /&gt;
      return;&lt;BR /&gt;
   run;&lt;BR /&gt;
   /* on lst&lt;BR /&gt;
   200-201,203,205-208,210-214,216&lt;BR /&gt;
   */&lt;BR /&gt;
[/pre]</description>
      <pubDate>Thu, 21 Oct 2010 19:42:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Printing-a-range-of-values/m-p/19926#M4085</guid>
      <dc:creator>chang_y_chung_hotmail_com</dc:creator>
      <dc:date>2010-10-21T19:42:51Z</dc:date>
    </item>
  </channel>
</rss>

