I'm working on a report that has copier/printing data and parsing the total pages printed is looking a little tricky. I have used PROC SQL to get the data from data source but now I'm working on a data step to get pages printed.
Most of the values are stored like:14 x Lgl/D and the total printed would be 14.
The other potential combinations: 14 x Lgl/D; 3 x Ltr; 86 x Ltr/D, separated by semi-colons. So for this transaction the total printed pages would 103 (14+3+86).
So I would need a data step that would handle all combinations and sum the total.
You can use a SAS variable in your DATA step along with SCAN to capture each semi-colon delimited, and then use another assignment statement (like more than one for simplicity in coding) to parse each of the sub-records within a "transaction" -- then output one accumulated observation (or otherwise use PROC SUMMARY).
Suggested Google advanced search argument, this topic / post:
scan function parse delimited records site:sas.com
if you use an input statement to read these columns, just add ';' to the delimiters defined on the infile statement. The default delimiter is a blank, so you would be adding the option to the infile statement like
input 'the file you read' dlm=' ;' other options like lrecl=1000 and truncover ;
copies=substr(copy_pages,1, index(copy_pages,'x')-1); >>only 1 value is stored in the row
IF findc(Copy_Pages, ';')>1 then;
do while (findc(copy_pages, ';')=0); >>> loop for more than one
Here is one sample approach using a DO/END to parse through each logical within a physical record:
10 data _null_;
11 infile "c:\temp\parse_data_sas.txt";
12 input ;
13 length tempvar $100;
14 do i=1 to countw(_infile_,';');
15 tempvar = scan(_infile_,i,';');
16 putlog _all_;
17 * add code here to parse each sub-field. ;
NOTE: The infile "c:\temp\parse_data_sas.txt" is:
RECFM=V,LRECL=256,File Size (bytes)=43,
tempvar=14 x Lgl/D i=1 _ERROR_=0 _INFILE_=14 x Lgl/D; 3 x Ltr; 86 x Ltr/D _N_=1
tempvar=3 x Ltr i=2 _ERROR_=0 _INFILE_=14 x Lgl/D; 3 x Ltr; 86 x Ltr/D _N_=1
tempvar=86 x Ltr/D i=3 _ERROR_=0 _INFILE_=14 x Lgl/D; 3 x Ltr; 86 x Ltr/D _N_=1
tempvar=18 x Lgl/D i=1 _ERROR_=0 _INFILE_=18 x Lgl/D _N_=2
NOTE: 2 records were read from the infile "c:\temp\parse_data_sas.txt".
The minimum record length was 10.
The maximum record length was 31.
NOTE: DATA statement used (Total process time):
real time 0.02 seconds
cpu time 0.01 seconds