BookmarkSubscribeRSS Feed
RConly
Calcite | Level 5

Hi,
I have a dilema, I'm trying to create a dataset from a text file but I want to create one observation but get data from multiple lines in the text file. Here is an example. When the line begins with VCR* I want to return the data after, which is a ticket number. Then further down in the list, I want to pull if we sent the revoke comand TRUE or FALSE. The ending data set would have two columns: TICKET_NO      REVOKED
0011730346500 TRUE

****** ****** ****** ****** ******
VCR*0011730346500<
VIRTUAL COUPON RECORD
0011730346500         NAME-

TTL NBR OF CPNS- 2 DATE OF ISSUE-10MAR16 PNR-XXXXXX    10MAR16
FF NBR-AA  44CPH96
CC-AXXXXXXXXXXXX1002
CPN A/L FLT  CLS DATE   BRDOFF  TIME  ST F/B           STAT
 1  AA  8145  N  27MAR  YVRYYZ  1130P OK NA07ZNH5      USED
 2X AA  3783  N  28MAR  YYZPHL  959A  OK NA07ZNH5      OK
FARE CAD    TAX   CA TAX    XG TAX   XT
     TOTAL CAD 
FARE CALC YVR AA X/YTO AA PHLNUCEND ROE XT
          SQUSYCXYXA
FCMI-2
FORM OF PAYMENT
FOP-AXXXXXXXXXXXX1002           EXP-  APPROVAL CODE-
DATE OF ISSUE-10MAR16     ISSUED AT-YYZ    S7S1 A84           #
***** ***** *****
**** Found coupon with OK status: true
**** PNR has been purged: false
*XXXXX*IA<
#NO ITIN#
***** ***** *****
***** Send revoke command: true
VCR#REVOKE-PNR XXXXXX/10-MAR-16 WAS NOT CANCELED PRIOR TO SCHEDU
LED DEPARTURE DATE // TICKET HAS NO VALUE //<
VCR REVOKED
***** ***** *****

2 REPLIES 2
LinusH
Tourmaline | Level 20
One way is to define ticket_no with REATIN. Assign both your variables with substr() or other char function you prefer, based on the automatic _infile_ variable.
Once you assigned revoked, do an explicit output.
Data never sleeps
Kurt_Bremser
Super User
data have;
infile cards truncover;
input inline $50.;
cards;
****** ****** ****** ****** ******
VCR*0011730346500<
VIRTUAL COUPON RECORD
0011730346500         NAME-
TTL NBR OF CPNS- 2 DATE OF ISSUE-10MAR16 PNR-XXXXXX    10MAR16
FF NBR-AA  44CPH96
CC-AXXXXXXXXXXXX1002
CPN A/L FLT  CLS DATE   BRDOFF  TIME  ST F/B           STAT
 1  AA  8145  N  27MAR  YVRYYZ  1130P OK NA07ZNH5      USED
 2X AA  3783  N  28MAR  YYZPHL  959A  OK NA07ZNH5      OK
FARE CAD    TAX   CA TAX    XG TAX   XT
     TOTAL CAD 
FARE CALC YVR AA X/YTO AA PHLNUCEND ROE XT
          SQUSYCXYXA
FCMI-2
FORM OF PAYMENT
FOP-AXXXXXXXXXXXX1002           EXP-  APPROVAL CODE-
DATE OF ISSUE-10MAR16     ISSUED AT-YYZ    S7S1 A84           #
***** ***** *****
**** Found coupon with OK status: true
**** PNR has been purged: false
*XXXXX*IA<
#NO ITIN#
***** ***** *****
***** Send revoke command: true
VCR#REVOKE-PNR XXXXXX/10-MAR-16 WAS NOT CANCELED PRIOR TO SCHEDU
LED DEPARTURE DATE // TICKET HAS NO VALUE //<
VCR REVOKED
***** ***** *****
;
run;

data want (keep=ticket_no revoked);
set have end=done;
retain
  ticket_no 0
  revoked 'false'
;
if substr(inline,1,4) = 'VCR*'
then ticket_no = input(substr(inline,5,length(inline)-5),best20.);
if substr(inline,1,4) = 'VCR#' and substr(inline,5,10) = 'REVOKE-PNR'
then revoked = 'true';
if done then output;
run;

If you want "revoked" to be truly boolean, set it to 0 in the retain statement and 1 when the right condition is encountered.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 963 views
  • 0 likes
  • 3 in conversation