Help using Base SAS procedures

Columnize rows of data using SAS on the mainframe

Reply
N/A
Posts: 0

Columnize rows of data using SAS on the mainframe

Hello all,

I'm a new SAS user on the mainframe.I have a dataset with rows of data. I need to format my output to be in columns. My current format is-
000001 MAILBOX ID=COMPANY#1
000002 BATCHID='DESCRIP#1'
000003 DSN=DATASETA
000001 MAILBOX ID=COMPANY#2
000002 BATCHID='DESCRIP#2'
000003 DSN=DATASETB

Target Output-
MAILBOX ID=COMPANY#1 BATCHID=DESCRIP#1 DSN=DATASETA
MAILBOX ID=COMPANY#2 BATCHID=DESCRIP#2 DSN=DATASETB

Could someone assist me? Thank you

I
Super Contributor
Super Contributor
Posts: 3,174

Re: Columnize rows of data using SAS on the mainframe

I would say that you have to objectives to accomplish here, as follows:

1) parse the input data using a DATA step and use a key variable to identify each unique "set" of rows (likely the first input data field as I see it). Explore the use of the SAS INPUT statement in your DATA step to read the first and second character fields (must use a RETAIN or better suggest using a DO UNTIL(EOF); / END loop instead to avoid the RETAIN stmt) and only increment the "set identifier" variable with each new input data field value "000001". Sample DATA step:

FILENAME INDATA "your_input_data_file_name";
DATA ;
INFILE INDATA ... END=EOF;
DO UNTIL(EOF);
* your INPUT and data interpretation logic goes here;
* ;
* your SAS OUTPUT logic goes here. ;
END;
STOP;
RUN;

2) sort your SAS temporary file by the "set identifier" variable.

3) explore using PROC TRANSPOSE to "horizontal-ize" your SAS temp file.

4) use PROC PRINT or some other PROC or DATA step technique to generate your "Target Output" - the key point here is that you can list your "transposed" variables as a generic prefix in your VAR statement with PROC PRINT. Sample PROC PRINT construct:

OPTIONS NOCENTER LS=MAX;
PROC PRINT U NOOBS...;
VAR your_transposed_variable_prefix: ; /* note the trailing colon char */
RUN;

For consideration, the SAS support http://support.sas.com/ website has SAS-hosted documentation and also supplemental technical code samples and conference topic-oriented papers, related to these SAS programming and data transformation techniques.


Scott Barry
SBBWorks, Inc.
Ask a Question
Discussion stats
  • 1 reply
  • 93 views
  • 0 likes
  • 2 in conversation