Hi - I'm trying to read in a raw text file (.f03), that isn't delimited consistently throughout. I'm able to read it in using a proc import dbms=csv option, and it puts everything into one column. I essentially want to be able to pull 2 different statistics out of this entire file. Is there a way to scan the one variable to keep the stat that comes after "ESTIMATED PROPORTION CONSISTENTLY CLASSIFIED ="? This only appears once in the file.
data try;
set testing;
if find(var1,'estimated proportion consistently classified','i')>0 then do;
value=scan(var1,-1)+0;
output;
end;
run;
Sure.
In a data step, use the FIND function to see if the line has ESTIMATED PROPORTION CONSISTENTLY CLASSIFIED
If so, then use the SCAN function to retrieve the last "word" which in this case is .875, convert character to numeric, then output to the data set.
Thank you! Is there anyway you can give me a syntax example of what you're thinking? I'm having trouble getting the scan function to work without explicitly stating what that statistic is.
@NR13 wrote:
Thank you! Is there anyway you can give me a syntax example of what you're thinking? I'm having trouble getting the scan function to work without explicitly stating what that statistic is.
If the line of text has been found to have the desired text string of ESTIMATED PROPORTION CONSISTENTLY CLASSIFIED, then you can use the SCAN function like this (assuming we are not very creative and the text string is a variable named TEXTSTRING)
number = scan(textstring,-1);
I'm sorry - I know i'm probably doing something stupid. This is what I'm trying:
Data Try;
Set Testing;
Correct=Scan(find(Var1,"ESTIMATED PROPORTION CONSISTENTLY CLASSIFIED"),-1);
Run;
data try;
set testing;
if find(var1,'estimated proportion consistently classified','i')>0 then do;
value=scan(var1,-1)+0;
output;
end;
run;
You're the best - thank you!!
You can also use a column "pointer" based on the value of text. If the key text is not found then nothing would be read. Keep only the records with values. A raw example;
data junk; infile datalines missover; input @"Some text" x; datalines; Some text 123 No key text 456 893 Some text 333 ; run;
And to keep only records with the value:
data junk; infile datalines missover; input @"Some text" x; if x ne .; datalines; Some text 123 No key text 456 893 Some text 333 ; run;
I have below data in an input file. I want to scan using a key word in each line and then want the ouput as below
Input File:
Code 201 Created
Date: Mon, 10 Sep 2018 08:30:56 GMT
Location: Asia, Singapore
Length: 150
Output:
Col1 | Col2 | Col3 | Col4 |
201 | Mon, 10 Sep 2018 08:30:56 GMT | Asia, Singapore | 150 |
Col1: After Code, get the 3 digits
Col2: After "Date: " and till end
Col3: After "Location: " and till end
Col4: After "Length: " and till end
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.