BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
rmacarthur
Pyrite | Level 9

Hi SAS Friends, 

Am trying to import several lines of text to create a single SAS variable, with each text line ending up as 1 row.

I have gotten this to work except for the following line of text.  In the data step import, SAS won't highlight it yellow, and reports,

"ERROR 180-322: Statement is not valid or it is used out of proper order."

I have tried several ways to make it work without success. 

Here is the code and single row text string.

How can the code be modified to import the text string, or what obvious thing is not being done?

Thank you

 

data want		; 
   	infile datalines	truncover ;
	input	text $1000.			;
	datalines	;
Drug products listed here and been evaluated by the Nacho Libre Committee, and considered necessary for meeting the needs of animals, minerals, and vegetables. Also, products stored on the hot dog carts and kit kat bars are included.  Commonly used infusion solutions (0.9% Humdrum chloride, USP; 5% chocolate, USP) are also included.;
run;
1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

You don't have a valid DATALINES statement.  Where is the closing semi-colon?

You don't need a RUN: statement after the end of the data step.  When you have in-line data the data step ends at the end of the data lines.

 

AND since your data include semicolons you actually need a DATALINES4 statement. 

 

Also your text seems to be riddled with randomly placed tab characters.  You really should not have ANY tab characters in program files.  But if you do have them then only use them at the start of a line.  Place them anywhere else and they will just cause your program to look jumbled.

 

Do you want each LINE to become one observation?

data want ; 
  infile datalines truncover ;
  input text $1000. ;
datalines4 ;
Drug products listed here and been evaluated by the Nacho Libre Committee, and considered necessary for meeting the needs of animals, minerals, and vegetables. Also, products stored on the hot dog carts and kit kat bars are included.  Commonly used infusion solutions (0.9% Humdrum chloride, USP; 5% chocolate, USP) are also included.;
;;;;

Or do you want ALL of the lines to become one observation?  If so do you want to put anything in between them?

data want ; 
  infile datalines truncover eof=eof;
  length text $1000 ;
  input;
  text = catx(' ',text,_infile_);
  return;
eof:
  output;
datalines4 ;
Drug products listed here and been evaluated by the Nacho Libre Committee, 
and considered necessary for meeting the needs of animals, minerals, and vegetables. 
Also, products stored on the hot dog carts and kit kat bars are included.  Commonly 
used infusion solutions (0.9% Humdrum chloride, USP; 5% chocolate, USP) are also included.;
;;;;

View solution in original post

4 REPLIES 4
Tom
Super User Tom
Super User

You don't have a valid DATALINES statement.  Where is the closing semi-colon?

You don't need a RUN: statement after the end of the data step.  When you have in-line data the data step ends at the end of the data lines.

 

AND since your data include semicolons you actually need a DATALINES4 statement. 

 

Also your text seems to be riddled with randomly placed tab characters.  You really should not have ANY tab characters in program files.  But if you do have them then only use them at the start of a line.  Place them anywhere else and they will just cause your program to look jumbled.

 

Do you want each LINE to become one observation?

data want ; 
  infile datalines truncover ;
  input text $1000. ;
datalines4 ;
Drug products listed here and been evaluated by the Nacho Libre Committee, and considered necessary for meeting the needs of animals, minerals, and vegetables. Also, products stored on the hot dog carts and kit kat bars are included.  Commonly used infusion solutions (0.9% Humdrum chloride, USP; 5% chocolate, USP) are also included.;
;;;;

Or do you want ALL of the lines to become one observation?  If so do you want to put anything in between them?

data want ; 
  infile datalines truncover eof=eof;
  length text $1000 ;
  input;
  text = catx(' ',text,_infile_);
  return;
eof:
  output;
datalines4 ;
Drug products listed here and been evaluated by the Nacho Libre Committee, 
and considered necessary for meeting the needs of animals, minerals, and vegetables. 
Also, products stored on the hot dog carts and kit kat bars are included.  Commonly 
used infusion solutions (0.9% Humdrum chloride, USP; 5% chocolate, USP) are also included.;
;;;;
rmacarthur
Pyrite | Level 9

Thank you very much, the DATALINES4 statement approach works fine.

Can I ask, how did you find out there were "randomly placed tab characters" in the text? 

Much appreciated !

Tom
Super User Tom
Super User

I copied the text and pasted it into the SAS program editor.  When I tried to remove some of the hugh white space before the semicolon on the first line it jumped 7 positions to the left instead of just 1.

 

I then just use the command:

change '09'x ' ' all

to convert all of the tabs into spaces.

 

If you are using SAS/Studio the editor preferences can be changed to convert tabs into spaces.  So when you are typing you can hit the TAB key to indent, but it doesn't actually insert a TAB character. Instead if inserts enough spaces to move to the next tab stop you have also set in the preferences.

rmacarthur
Pyrite | Level 9

Thank you again, that's good to know, and extremely helpful!

Robert

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 719 views
  • 2 likes
  • 2 in conversation