BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
kazoli
Calcite | Level 5
Hello - I'm brand new to SAS and am struggling with something. I have SQL code stored in a .txt file. I would like to read the .txt file contents into a single string variable in SAS that can then be called in a PROC SQL statement in order to run a query. The .txt file does have a few parameters/variables inside it that I will need to replace once imported into SAS, but I'm able to do that successfully. Below is a sample of the code I'm currently using. This process is able to get the .txt file contents, but it concatenates the lines in a way that makes the query error out due to formatting issues. Any point in the right direction is greatly appreciated.
 
FILENAME msghtml "//mypath/myfile.txt"
data _null_;
length text $32767;
retain text '';
infile msghtml flowover dlmstr='//' end=last;
input;
text = catx(text,_infile);
run;
1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

You are creating the value in a dataset variable, but since you are using _NULL_ dataset it is not being written anywhere.  If you want to store it in a macro variable then you need to add a CALL SYMPUTX() function call. Use the LAST variable you created with the INFILE statement to know when to create the macro variable.

 

The DMLSTR= option is doing nothing in your data step.  Are you trying to remove end-of-line comments that are marked with // ?  If so then try reading the line into a variable instead of using the _INFILE_ automatic variable. 

data _null_;
  length sql line $32767;
  retain sql ;
  infile msghtml flowover dlmstr='//' end=last;
  input line ;
  sql = catx(' ',sql,line);
  if last then call symputx('sql',sql);
run;

View solution in original post

2 REPLIES 2
Tom
Super User Tom
Super User

You are creating the value in a dataset variable, but since you are using _NULL_ dataset it is not being written anywhere.  If you want to store it in a macro variable then you need to add a CALL SYMPUTX() function call. Use the LAST variable you created with the INFILE statement to know when to create the macro variable.

 

The DMLSTR= option is doing nothing in your data step.  Are you trying to remove end-of-line comments that are marked with // ?  If so then try reading the line into a variable instead of using the _INFILE_ automatic variable. 

data _null_;
  length sql line $32767;
  retain sql ;
  infile msghtml flowover dlmstr='//' end=last;
  input line ;
  sql = catx(' ',sql,line);
  if last then call symputx('sql',sql);
run;
kazoli
Calcite | Level 5

Perfect, that did the trick - thank you very much! I found a lot of this code elsewhere and tried to apply it to my case, but this has taught me more in this area. Thanks again!

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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.

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
  • 2 replies
  • 678 views
  • 0 likes
  • 2 in conversation