BookmarkSubscribeRSS Feed
deleted_user
Not applicable
I am trying to write a SAS program to read the text from a SAS program file.

Little more detailed explaination. Suppose I have a SAS program called myProg.sas
at location C:\MyFolder1\Myfolder2. I want to write a SAS program that will read the text from myProg.sas and then write it back to a text file to a destination location say
C:\MyOutputFolder.

To begin with,I wrote a small SAS program to read the SAS program text into a data set. My program looks like


data myData;

INFILE 'C:\DAG\SAS\Farmers\state_extract_forDAG.sas';

INPUT progText;

run;

I am getting error saying invalid data for progText. The log file errors are

------------------------------------------------------------------------------------------

NOTE: Invalid data for progText in line 2 1-4.
RULE: ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0
2 data employee; 51
progText=. _ERROR_=1 _N_=1
NOTE: Invalid data for progText in line 3 3-7.
3 input lastname $ 1-10 fname $ 12-21 ssn 23-31 status $ 33-38; 65
progText=. _ERROR_=1 _N_=2
NOTE: Invalid data for progText in line 4 1-11.




RULE: ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0

4 CHAR .datalines; 64
ZONE 0667666667322222222222222222222222222222222222222222222222222222
NUMR 94141C9E53B00000000000000000000000000000000000000000000000000000
progText=. _ERROR_=1 _N_=3
NOTE: Invalid data for progText in line 5 1-5.
5 Green Samual 888888888 Hourly 63
progText=. _ERROR_=1 _N_=4
NOTE: Invalid data for progText in line 6 1-7.
6 Brennon Carol 123456789 Salary 63
progText=. _ERROR_=1 _N_=5
NOTE: Invalid data for progText in line 7 1-4.
7 Wang Robert 999999999 Salary 63
progText=. _ERROR_=1 _N_=6
NOTE: Invalid data for progText in line 8 1-8.
8 Randolph Virginia 987654321 Salary 39
progText=. _ERROR_=1 _N_=7
NOTE: Invalid data for progText in line 9 1-1.
9 ; 1
progText=. _ERROR_=1 _N_=8
NOTE: Invalid data for progText in line 11 1-4.
11 data distance; 14
progText=. _ERROR_=1 _N_=9
NOTE: Invalid data for progText in line 12 1-5.
12 miles = 26.22; 14
progText=. _ERROR_=1 _N_=10
NOTE: Invalid data for progText in line 13 1-10.
13 kilometers = 1.61*miles; 24
progText=. _ERROR_=1 _N_=11
NOTE: Invalid data for progText in line 15 1-4.
15 proc print data = employee; 27
progText=. _ERROR_=1 _N_=12
NOTE: Invalid data for progText in line 17 1-4.
17 run; 4
progText=. _ERROR_=1 _N_=13
NOTE: 17 records were read from the infile 'C:\DAG\SAS\Farmers\Unit_Test_sample1.sas'.
The minimum record length was 0.
The maximum record length was 65.
NOTE: SAS went to a new line when INPUT statement reached past the end of a line.
NOTE: The data set WORK.MYDATA has 13 observations and 1 variables.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds

------------------------------------------------------------------------------------------------

I am getting character '.' in all observation of MYDATA dataset

The .sas program file I'm trying to read is given below

------------------------------------------------------------------------------------------------

data employee;
input lastname $ 1-10 fname $ 12-21 ssn 23-31 status $ 33-38;
datalines;
Green Samual 888888888 Hourly
Brennon Carol 123456789 Salary
Wang Robert 999999999 Salary
Randolph Virginia 987654321 Salary
;

data distance;
miles = 26.22;
kilometers = 1.61*miles;

proc print data = employee;

run;
---------------------------------------------------------------------------------------------

Appreciate any help.

Thanks,
Neel
7 REPLIES 7
Flip
Fluorite | Level 6
The error log shows progText as numeric. Try assigning is as a long string before the INPUT, or format the INPUT.
deleted_user
Not applicable
Thank You.

I kind of got it working with
------------------------------------------------------------------------------------
data myData;

INFILE 'C:\DAG\SAS\Farmers\Unit_Test_sample1.sas' DLM = ';';

LENGTH progText $ 200 ;
INPUT progText;

run;
--------------------------------------------------------------------------------------
I get every line of SAS program as one observation in the dataset

I want to write each of these lines into a text file at a sepcific location say
C:\DAG\MyFolder\myProg.txt

I was thinking I can use ODS. I couldn't locate how to specify a text file for ODS.
(I found abt csv,html & others though)

Any help?
Thanks,
Neelam
deleted_user
Not applicable
I was able to find the option for outputting to a text file

ODS listing file='someFile.txt'
deleted_user
Not applicable
Anyone knows how to get rid of line numbers in the output file.

I am getting the program text output to a .txt file. But I get line numbers which I don't want.

Any Help?

Thanks,
Neel
milts
Pyrite | Level 9
Hi Neel,

you used proc print to create the listing if i got it right. just add the noobs option in your proc print statement.

Regards,
Milton
deleted_user
Not applicable
Thanks Milton!

that helped..

Any way to avoid the following standard SAS system line in the output?

The SAS System 08:55 Thursday, September 3, 2009 4


Thanks,
Neelam
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
You can override the SAS-system default using:

OPTIONS NODATE NONUMBER;
TITLE;


Scott Barry
SBBWorks, Inc.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 7 replies
  • 1296 views
  • 0 likes
  • 4 in conversation