LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (August 1998, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Wed, 19 Aug 1998 15:11:20 EDT
Reply-To:     sxh04@HEALTH.STATE.NY.US
Sender:       "SAS(r) Discussion" <SAS-L@UGA.CC.UGA.EDU>
From:         Suhua Hu <sxh04@HEALTH.STATE.NY.US>
Subject:      How to create a flat file using PROC CONTENTS

I am trying to create a flat file and a file layout from the output of a PROC CONTENTS. Everything looks OK except one problems: all numeric variables got length of 8 rather than their orginal length.

See the attached program and output for details. Thanks.

data one; input id $char2. bgdate $char8. charvar $char5. num 1.; cards; 6A01/02/90AAAAA2 6A11/22/90BBBBB3 6A02/02/90CCCCC4 8B02/01/90DDDDD5 8B02/20/90EEEEE6 8B03/01/90FFFFF6 ;

proc contents data=one out=fileinfo(keep=name label length type format) position noprint;

proc format; value typefmt 1='num' 2='char';

data layout; set fileinfo end=end; prelen=lag(length); if _n_=1 then startpos=1; else startpos+prelen; if type=1 then do; format=trim(left(put(length,2.)))||'.'; end; else do; format='$char' ||trim(left(put(length,2.)))||'.'; end; n+1; call symput ('var'||left(put(n,3.)),name); call symput ('fmt'||left(put(n,3.)),format); if end then call symput('totvars',left(put(n,3.))); run;

proc print data=layout noobs; var name startpos length type format; format type typefmt.; run;

%macro vars; %do i=1 %to &totvars; &&var&i &&fmt&i %end; %mend vars;

data _null_; set one; file outfile noprint; put @2 %vars; run; endsas;

File layout:

NAME STARTPOS LENGTH TYPE FORMAT

BGDATE 1 8 char $char8. CHARVAR 9 5 char $char5. ID 14 2 char $char2. NUM 16 8 num 8.

Flat File:

01/02/90AAAAA6A 2 11/22/90BBBBB6A 3 02/02/90CCCCC6A 4 02/01/90DDDDD8B 5 02/20/90EEEEE8B 6 03/01/90FFFFF8B 6


Back to: Top of message | Previous page | Main SAS-L page