BookmarkSubscribeRSS Feed
deleted_user
Not applicable
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
1 REPLY 1
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
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.
What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 1 reply
  • 1151 views
  • 0 likes
  • 2 in conversation