Hello, I am trying reading one .acct extension file (ascii file) which has multiple values. each observation contain 10 variables and values are separated by space (as shown below). some values are in between double quotes (where they have different delimiters like space, hyphen in between one values as well). (sas 9.4 linux)
trying to give an example,
/homedir/test.acct file contains,
"some_char"
123.45
" "
"/rootdir/test.sh -parm1 -parm2"
"-param1 ' " "userid@test.com" " ' -param2 some_char"
-1
12345678910
"select[type==any] order[r12f:pg]"
60.0
"some-character"
I am trying reading using filename statement which is not working fine - test run fine but not getting values.
/*trying to read everything as character first to get initial dataset*/
filename test_file pipe "/homedir/test.acct";
data test;
infile test_file dsd dlm='09'x;
input
var1 $20
var2 $20
var3 $20
var4 $50
.
.
var10 $20;
run;
It appears that your data values appear on different rows. So you need to tell SAS which row has which variables.
One way is to use an / character to indicate the next variable starts on the next row.
From your example code something similar to this:
data test; infile test_file dsd dlm='09'x; input var1 $20 / var2 $20 / var3 $20 / var4 $50 . . / var10 $20; run;
HOWEVER you may have made some incorrect assumptions about variable lengths and types. It appears that row 2, 6 and 9 are more likely numeric.
Also take a close look at line 5. You actually have multiple variables if using list input. I have placed an | in between the things that SAS would see as a variable:
"-param1 ' " | "userid@test.com" | " ' -param2 some_char"
Each pair of double quotes encloses one value most likely.
Last using formats on input statements with list input can cause issues as you have them. If the first line doesn't contain 20 characters you may get messages about reading past end of line and apparently skipped values.
You might be better off defining your variables in an informat statement and then just have the variable names on the input statement.
You may also want to change
filename test_file pipe "/homedir/test.acct";
to
filename test_file "/homedir/test.acct";
unless test.acct is a script file that sends output to stdout. The PIPE part of the filename statement tells SAS the input to read should come from a program sending output to stdout. A common use is to direct the output of an ls command to generate filenames to be read by the data step: filename flist pipe "ls <options>";
I'd probably recommend first reading it entirely and seeing what it looks like. I would also consider parsing after I've read it in, rather than try and modify the INPUT step. Mostly because I find it harder.
Try this for starter, not sure why you specified pipe on the filename reference.
filename test_file "/homedir/test.acct";
data test;
infile test_file;
input;
x=_infile_;
run;
Not sure if the following is relevant but, if it is, definitely might be worth while considering: http://www.file-extension.org/extensions/acct
Art, CEO, AnalystFinder.com
Thanks all.
I am sorry but I just tried to show you how different values are in my file by placing them on different row.
infect file looks like this (10 variables for each observation)
"some_chars" 123.45 " " "/rootdir/test.sh -parm1 -parm2" "-param1 ' " "userid@test.com" " ' -param2 some_char" -1 12345678910 "select[type==any] order[r12fg]" 60.0 "some-characters"
"some_chars" 1.5 "sdljvkdvjkn " "/rootdir/test.sh -parm1 -parm2" "-param1 ' " "userid@test.com" " ' -param2 some_char" -1 12345678910 "select[type==any] order[r12fg]" 50 "some-long-characters"
"some_chars" 123.45 " " "/rootdir/test.sh -parm1 -parm2" "-param1 ' " "userid@test.com" " ' -param2 some_char" -1 12345678910 "some-different-char" 123.456 "some-characters"
Thanks - so may be I will need use @@ in end of the infile statement so that SAS can continue reading until it gets total 10 values for one observation.
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!
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.