<?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: Newbie data question in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Newbie-data-question/m-p/38941#M7878</link>
    <description>This is handled by some classic data step programming. Could be done i thousands of ways, here's one. This example involves some help variables, retain, if-then-else and scans. If you are going to do more of this kind est you should consider taking a SAS programming class.&lt;BR /&gt;
&lt;BR /&gt;
data report;&lt;BR /&gt;
	infile '~/reportdat.dat';&lt;BR /&gt;
	input;&lt;BR /&gt;
	length station origin $10 &lt;BR /&gt;
			 originCount 8 &lt;BR /&gt;
			 originNext $1;&lt;BR /&gt;
	retain station originCount originNext;&lt;BR /&gt;
	firstVar = scan(_infile_,1,' ');&lt;BR /&gt;
	if firstVar eq 'STATION:' then do;&lt;BR /&gt;
		station = scan(_infile_,2,' ');&lt;BR /&gt;
		originCount = 0;&lt;BR /&gt;
		originNext = 'N';&lt;BR /&gt;
	end;&lt;BR /&gt;
	else if firstVar eq '(data' then originNext = 'Y';&lt;BR /&gt;
	else if firstVar eq 'TTL' or &lt;BR /&gt;
				originNext = 'Y' and originCount lt 5 and firstVar not =: '-' then do;&lt;BR /&gt;
		origin = firstVar;&lt;BR /&gt;
		sales2008 = input(scan(_infile_,2,' '),best.);&lt;BR /&gt;
		sales2007 = input(scan(_infile_,3,' '),best.);&lt;BR /&gt;
		if firstVar eq 'TTL' then originNext = 'N';&lt;BR /&gt;
		else originCount+1;&lt;BR /&gt;
		output;&lt;BR /&gt;
	end;&lt;BR /&gt;
	drop firstVar originCount originNext;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
Regards,&lt;BR /&gt;
Linus</description>
    <pubDate>Thu, 14 Aug 2008 14:04:41 GMT</pubDate>
    <dc:creator>LinusH</dc:creator>
    <dc:date>2008-08-14T14:04:41Z</dc:date>
    <item>
      <title>Newbie data question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Newbie-data-question/m-p/38940#M7877</link>
      <description>Hi All,&lt;BR /&gt;
&lt;BR /&gt;
I am trying to automate a process of reading from reports that are not really formatted in a great way but am failing miserably at it.  Can anyone help me?  The data is in a format roughly like this:&lt;BR /&gt;
&lt;BR /&gt;
REPORT XXX&lt;BR /&gt;
STATION: ORD&lt;BR /&gt;
==================&lt;BR /&gt;
REPORT HEADERS&lt;BR /&gt;
REPORT HEADERS2&lt;BR /&gt;
(data starts below)&lt;BR /&gt;
Origin1 sales2008 sales 2007&lt;BR /&gt;
Origin2 sales2008 sales 2007&lt;BR /&gt;
Origin3 sales2008 sales 2007&lt;BR /&gt;
.&lt;BR /&gt;
.&lt;BR /&gt;
.&lt;BR /&gt;
.&lt;BR /&gt;
------------------&lt;BR /&gt;
TTL&lt;BR /&gt;
&lt;BR /&gt;
This repeats for 40 stations all in the same file.  The number of origins can change and is not fixed.  What I would like to do is:&lt;BR /&gt;
&lt;BR /&gt;
1) Read in station name&lt;BR /&gt;
2) read in top 5 origins&lt;BR /&gt;
3) read in total (ttl above)&lt;BR /&gt;
4) Go to the next station.&lt;BR /&gt;
&lt;BR /&gt;
Any help would be greatly appreciated (and help me learn more about SAS).&lt;BR /&gt;
&lt;BR /&gt;
Many thanks .</description>
      <pubDate>Thu, 14 Aug 2008 05:54:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Newbie-data-question/m-p/38940#M7877</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-08-14T05:54:36Z</dc:date>
    </item>
    <item>
      <title>Re: Newbie data question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Newbie-data-question/m-p/38941#M7878</link>
      <description>This is handled by some classic data step programming. Could be done i thousands of ways, here's one. This example involves some help variables, retain, if-then-else and scans. If you are going to do more of this kind est you should consider taking a SAS programming class.&lt;BR /&gt;
&lt;BR /&gt;
data report;&lt;BR /&gt;
	infile '~/reportdat.dat';&lt;BR /&gt;
	input;&lt;BR /&gt;
	length station origin $10 &lt;BR /&gt;
			 originCount 8 &lt;BR /&gt;
			 originNext $1;&lt;BR /&gt;
	retain station originCount originNext;&lt;BR /&gt;
	firstVar = scan(_infile_,1,' ');&lt;BR /&gt;
	if firstVar eq 'STATION:' then do;&lt;BR /&gt;
		station = scan(_infile_,2,' ');&lt;BR /&gt;
		originCount = 0;&lt;BR /&gt;
		originNext = 'N';&lt;BR /&gt;
	end;&lt;BR /&gt;
	else if firstVar eq '(data' then originNext = 'Y';&lt;BR /&gt;
	else if firstVar eq 'TTL' or &lt;BR /&gt;
				originNext = 'Y' and originCount lt 5 and firstVar not =: '-' then do;&lt;BR /&gt;
		origin = firstVar;&lt;BR /&gt;
		sales2008 = input(scan(_infile_,2,' '),best.);&lt;BR /&gt;
		sales2007 = input(scan(_infile_,3,' '),best.);&lt;BR /&gt;
		if firstVar eq 'TTL' then originNext = 'N';&lt;BR /&gt;
		else originCount+1;&lt;BR /&gt;
		output;&lt;BR /&gt;
	end;&lt;BR /&gt;
	drop firstVar originCount originNext;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
Regards,&lt;BR /&gt;
Linus</description>
      <pubDate>Thu, 14 Aug 2008 14:04:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Newbie-data-question/m-p/38941#M7878</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2008-08-14T14:04:41Z</dc:date>
    </item>
    <item>
      <title>Re: Newbie data question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Newbie-data-question/m-p/38942#M7879</link>
      <description>Thanks so much for the tip Linus.  You have opened my eyes.  It is sure great learning tricks like this from other users.&lt;BR /&gt;
&lt;BR /&gt;
All the best.</description>
      <pubDate>Thu, 14 Aug 2008 16:06:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Newbie-data-question/m-p/38942#M7879</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-08-14T16:06:00Z</dc:date>
    </item>
  </channel>
</rss>

