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:
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.
This parameter file defines global macro variables and their values. Such that log_transform is a macro variable with value 'N'.
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;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.