<?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: Treating '.' as a character in group by in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Treating-as-a-character-in-group-by/m-p/44385#M9092</link>
    <description>Thanks Scott.. will check one by one as you suggested and update in this thread...</description>
    <pubDate>Sun, 14 Jun 2009 18:10:44 GMT</pubDate>
    <dc:creator>deleted_user</dc:creator>
    <dc:date>2009-06-14T18:10:44Z</dc:date>
    <item>
      <title>Treating '.' as a character in group by</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Treating-as-a-character-in-group-by/m-p/44383#M9090</link>
      <description>Hi,&lt;BR /&gt;
We are using SAS V8.2 in our Mainframe work shop.&lt;BR /&gt;
&lt;BR /&gt;
My requirement is to calculate count of unique variables. Here is the code I have used.&lt;BR /&gt;
&lt;BR /&gt;
DATA INPUT1;                                     &lt;BR /&gt;
INFILE INPUT1;                                   &lt;BR /&gt;
   INPUT MNAME   $ 1-25;           &lt;BR /&gt;
RUN;                                             &lt;BR /&gt;
&lt;BR /&gt;
 DATA NEWFI;                               &lt;BR /&gt;
      SET INPUT1;                          &lt;BR /&gt;
      BY MNAME;                            &lt;BR /&gt;
 IF FIRST.MNAME THEN SUM=0;                &lt;BR /&gt;
    SUM + 1;                               &lt;BR /&gt;
 IF LAST.MNAME THEN OUTPUT;                &lt;BR /&gt;
&lt;BR /&gt;
  RUN;                                     &lt;BR /&gt;
&lt;BR /&gt;
  PROC SORT DATA=NEWFI;                    &lt;BR /&gt;
       BY DESCENDING SUM;                  &lt;BR /&gt;
&lt;BR /&gt;
 PROC PRINT;                &lt;BR /&gt;
&lt;BR /&gt;
I have input data in the format&lt;BR /&gt;
&lt;BR /&gt;
----+----1----+----2----+&lt;BR /&gt;
                              (spaces)&lt;BR /&gt;
                              (spaces)&lt;BR /&gt;
                              (spaces)&lt;BR /&gt;
.                             (one dot)&lt;BR /&gt;
&lt;BR /&gt;
I am expecting the output as&lt;BR /&gt;
&lt;BR /&gt;
MNAME                 SUM&lt;BR /&gt;
---------------------------------------&lt;BR /&gt;
(SPACES)                3&lt;BR /&gt;
.                       1&lt;BR /&gt;
&lt;BR /&gt;
But I am receiving the output as&lt;BR /&gt;
&lt;BR /&gt;
MNAME                 SUM&lt;BR /&gt;
---------------------------------------&lt;BR /&gt;
(SPACES)                      4&lt;BR /&gt;
&lt;BR /&gt;
Kindly correct the above code to get the expected result.&lt;BR /&gt;
&lt;BR /&gt;
Thanks,&lt;BR /&gt;
kris

Corrected the SAS output display.&lt;BR /&gt;
&lt;BR /&gt;
    &lt;BR /&gt;
Message was edited by: kris_madras</description>
      <pubDate>Sun, 14 Jun 2009 06:47:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Treating-as-a-character-in-group-by/m-p/44383#M9090</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-06-14T06:47:07Z</dc:date>
    </item>
    <item>
      <title>Re: Treating '.' as a character in group by</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Treating-as-a-character-in-group-by/m-p/44384#M9091</link>
      <description>Review the SASLOG output closely - you will see a SAS diagnostic message which you may have overlooked, shown below:&lt;BR /&gt;
&lt;BR /&gt;
NOTE: SAS went to a new line when INPUT statement reached past the end of a line.&lt;BR /&gt;
&lt;BR /&gt;
Also, you most likely do not have a fixed-length (RECFM=F) record/file layout providing data (again info revealed in the INFILE diagnostic of your SAS log) in columns 1 through 25 on each record, so SAS is assigning a missing value.&lt;BR /&gt;
&lt;BR /&gt;
First you must specify TRUNCOVER or MISSOVER, possibly -- review the INFILE statement coding.  And second you want to review the INPUT statement processing to handle the shorter record length, rather than using the INPUT statement you have coded.  I don't believe that this behavior is unique to the mainframe either - it is related to the input file layout and record format for your data.&lt;BR /&gt;
&lt;BR /&gt;
For diagnostic information (self-debugging), consider adding either a :&lt;BR /&gt;
&lt;BR /&gt;
LIST;&lt;BR /&gt;
&lt;BR /&gt;
...or....  (tip: get to SAS 9 as soon as possble so you can use PUTLOG -- and so you can be on a supported SAS version):&lt;BR /&gt;
&lt;BR /&gt;
FILE LOG;&lt;BR /&gt;
PUT _ALL_;  &lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Also, consider adding a sort step for your input file before you use BY processing.  And I would encourage you to code a LENGTH statement to declare MNAME length explicitly.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Sun, 14 Jun 2009 13:14:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Treating-as-a-character-in-group-by/m-p/44384#M9091</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2009-06-14T13:14:51Z</dc:date>
    </item>
    <item>
      <title>Re: Treating '.' as a character in group by</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Treating-as-a-character-in-group-by/m-p/44385#M9092</link>
      <description>Thanks Scott.. will check one by one as you suggested and update in this thread...</description>
      <pubDate>Sun, 14 Jun 2009 18:10:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Treating-as-a-character-in-group-by/m-p/44385#M9092</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-06-14T18:10:44Z</dc:date>
    </item>
    <item>
      <title>Re: Treating '.' as a character in group by</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Treating-as-a-character-in-group-by/m-p/44386#M9093</link>
      <description>Hello Kris,&lt;BR /&gt;
&lt;BR /&gt;
Here is a small example (based on the code you pasted) that you could easily adapt upon your needs &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;BR /&gt;
&lt;BR /&gt;
Regards,&lt;BR /&gt;
Florent&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
DATA INPUT1 (drop= i);&lt;BR /&gt;
	format MNAME $25.;&lt;BR /&gt;
&lt;BR /&gt;
	/* Spaces */&lt;BR /&gt;
	do i=1 to 3;&lt;BR /&gt;
		MNAME='                         ';&lt;BR /&gt;
		output;&lt;BR /&gt;
	end;&lt;BR /&gt;
&lt;BR /&gt;
	/* Text */&lt;BR /&gt;
	do i=1 to 2;&lt;BR /&gt;
		MNAME='This is some text';&lt;BR /&gt;
		output;&lt;BR /&gt;
	end;&lt;BR /&gt;
&lt;BR /&gt;
	/* Dot */&lt;BR /&gt;
	do i=1 to 6;&lt;BR /&gt;
		MNAME=.;&lt;BR /&gt;
		output;&lt;BR /&gt;
	end;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
proc sql;&lt;BR /&gt;
	create table NEWFI as&lt;BR /&gt;
		select 	MNAME,&lt;BR /&gt;
				count(missing(MNAME)) as SUM&lt;BR /&gt;
		from INPUT1&lt;BR /&gt;
		group by MNAME&lt;BR /&gt;
		order by SUM desc;&lt;BR /&gt;
quit;</description>
      <pubDate>Fri, 10 Jul 2009 13:13:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Treating-as-a-character-in-group-by/m-p/44386#M9093</guid>
      <dc:creator>Florent</dc:creator>
      <dc:date>2009-07-10T13:13:55Z</dc:date>
    </item>
    <item>
      <title>Re: Treating '.' as a character in group by</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Treating-as-a-character-in-group-by/m-p/44387#M9094</link>
      <description>One thought, if the sole purpose of the second data step is to get a count of the unique variables it has one problem in that the data should be sorted by the variable you are trying to count.&lt;BR /&gt;
&lt;BR /&gt;
Another approach would be to use some thing like:&lt;BR /&gt;
&lt;BR /&gt;
Proc freq data=INPUT1 order=freq;&lt;BR /&gt;
   table mname /nopercent missing;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
Your example actually didn't have spaces but were null strings (empty).&lt;BR /&gt;
From the online help for input statement, column:&lt;BR /&gt;
&lt;BR /&gt;
&lt;B&gt;Both leading and trailing blanks within the field are ignored&lt;/B&gt;. Therefore, if numeric values contain blanks that represent zeros or if you want to retain leading and trailing blanks in character values, read the value with an informat. See INPUT Statement, Formatted.&lt;BR /&gt;
&lt;BR /&gt;
Missing Values&lt;BR /&gt;
Missing data do not require a place-holder. The INPUT statement interprets a blank field as missing and reads other values correctly. If a numeric or &lt;B&gt;character field contains a single period, the variable value is set to missing.&lt;/B&gt;</description>
      <pubDate>Fri, 10 Jul 2009 22:13:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Treating-as-a-character-in-group-by/m-p/44387#M9094</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2009-07-10T22:13:22Z</dc:date>
    </item>
  </channel>
</rss>

