BookmarkSubscribeRSS Feed
lydiawawa
Lapis Lazuli | Level 10

Hi,

I'm importing a parameter file in txt form with no title row such as the following:

byvars             TEST16X GIO
log_transform      N
y_intercept        Y
exclude_outliers   N
exclude_einmos     N

Because it is a parameter file, the length of the two columns will not be fixed. The following is the problematic code I created to import the txt file. The two columns are concatenated instead of splitting into individual columns:

data test1;
	infile "files/parameters.txt" DELIMITER='09'x col=Colpoint
	length=linelen;
	length pname $30 pvalue $10;

	input @1 pname $ @;
	varlen=linelen - colpoint + 1;
    input pvalue $varying1024. varlen;
	call symputx('pname', STRIP(pvalue));
run;

Output:

lydiawawa_0-1673991736794.png

 

 

 

3 REPLIES 3
Astounding
PROC Star

The data you posted uses spaces as delimiters, not tabs.  The program to read it could be as simple as:

 

data want;
   infile "files/parameters.txt";
   length pname $ 30 pvalue $ 10;
   input pname pvalue;
   call symputx(pname, pvalue);
run;

It's not clear why you want macro variables here, and if you don't need them you could remove the last statement.

lydiawawa
Lapis Lazuli | Level 10

This parameter file defines global macro variables and their values. Such that log_transform is a macro variable with value 'N'.

Tom
Super User Tom
Super User

Do you have specifications for how the file was created?

Is the white space between the two values spaces or a single tab character?  Your program is saying it should be a single TAB character, but the text you posted has spaces instead.

 

If it is a tab character then using DSD should work, as long as any PVALUE that has a tab in it is quoted.

data parameters;
  infile "files/parameters.txt" dsd dlm='09'x truncover ;
  input pname :$32. pvalue :$200.;
  call symputx(pname,pvalue);
run;

If the delimiter is a space (or the PVALUE has embedded delimiters without quotes) and parameter name does not contain any spaces then you can just use formatted input for the PVALUE. Using formatted input will read through and delimiters.

data parameters;
  infile "files/parameters.txt" truncover ;
  input pname :$32. pvalue $200.;
  call symputx(pname,pvalue);
run;

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
  • 3 replies
  • 406 views
  • 3 likes
  • 3 in conversation