0
votes

I'd like to get a list of formats used for each variable in the INPUT section. For example, say, we have a csv file and manually import data into SAS. In the code section, we will have smth like that:

DATA WORK.SAS_data_1;
LENGTH
    A                  8
    B                $ 9
    C                  8
    D                  8
    E                  8 ;
FORMAT
    A                BEST1.
    B                $CHAR9.
    C                MMDDYY10.
    D                BEST1.
    E                BEST3. ;
INFORMAT
    A                BEST1.
    B                $CHAR9.
    C                MMDDYY10.
    D                BEST1.
    E                BEST3. ;
INFILE 'C:\Users\AppData\Local\Temp\SEG3592\SAS_data_1-ab6243ce7f064047b5e010c113d2f6a3.txt'
    LRECL=27
    ENCODING="WLATIN1"
    TERMSTR=CRLF
    DLM='7F'x
    MISSOVER
    DSD ;
INPUT
    A                : ?? BEST1.
    B                : $CHAR9.
    C                : ?? MMDDYY9.
    D                : ?? BEST1.
    E                : ?? BEST3. ;
RUN;

I'd like to know what formats are used in the INPUT section, that is: BEST1. for A, $CHAR9. for B, MMDDYY9. for C, etc.

I've found the code that summaries the format and informat for each variable in SASHELP.CARS dataset but I cannot find the format used in the INPUT section. Does anyone know where to find it? At times (for numerical variables) these formats can be different. Here is the code:

proc sql noprint ;
create table varlist as
select memname,varnum,name,type,length,format,informat, label
from dictionary.columns
where libname='SASHELP' and memname='CARS'
;
quit;

Thank you.

2
@Ken. I'm sorry, I never wanted to create such an impression. I probably had my caps lock key on while typing this question. So sorry.Yelena
No problem. Thank you for being polite. :-)Ken White
Do you have examples of "formats [that] can be different" from what you get with the dictionary query? (I'm guessing the differences occur when BEST. is used at the import stage?)Dominic Comtois
format and informat are different - you almost certainly mean informat (the bit in the input code would be an informat).Joe
Yes, I've just found that in the INPUT section we use INFORMAT. Thank you very much, Joe.Yelena

2 Answers

2
votes

It's not possible to recover the original input code used for a particular dataset. If informats were used with the INFORMAT statement, then you can see those (as you did in your example).

But determining whether a dataset was read in like this:

data have;
  input x;
  datalines;
1
2
3
4
5
;;;;
run;

Or like this:

data have;
  input @1 x 1.;
datalines;
1
2
3
4
5
;;;;
run;

Or even this:

data have;
  input @1 x 12.;
datalines;
1
2
3
4
5
;;;;
run;

All would appear exactly identically in SAS and have exactly identical metadata. The only way to know how they were input would be to have access to the input program and log it.

0
votes

SAS does not need be told how to convert most strings into values. In your example only the variable C needs to use special informat so that SAS knows how to interpret the text as a date.

You can use the INFORMAT statement to attach an informat specification to a variable in a dataset. However that metadata does not really serve much purpose in SAS, except perhaps if you are still using PROC FSEDIT.

If you want to store instructions on how your text file (CSV files are text files) is formatted then you should store that information into another document (or database). Or just save the SAS program.