Help using Base SAS procedures

Identifying Date, Currency and Time variables

Reply
N/A
Posts: 1

Identifying Date, Currency and Time variables

I am trying to write a program that will return details about variables in a dataset.  The code below is close to what I need:

libname VARLIST "<location>";

proc sql;
create table dset_details as
select memname,
memtype,
name,
type,
format
from dictionary.columns
where libname = "VARLIST";
quit;

However, type only returns "num" for Date, Currency and Time variables.

Where would I find data that returns the type as Date, Currency and Time similar to the view I would get if I accessed the dataset properties from Enterprise Guide

(i.e. right click on a dataset in a SAS EG project and select "Properties" > "Columns")

Thanks!

Super Contributor
Posts: 297

Re: Identifying Date, Currency and Time variables

Posted in reply to bbrowne81

It depends what you are trying to do.  If you just want a quick list of how the data is presented in the file you could use;

proc sql;

describe table sashelp.cars;

quit;

This will describe the table's columns in the log.

If you want the information output to a dataset;

proc contents data=sashelp.cars out=want;

run;

or

proc sql;

create table dset_details as

select *

from dictionary.columns

where libname = "SASHELP" and memname = 'CARS';

quit;

The format used can be found in the format variable.

Regards,

Scott

Super Contributor
Posts: 339

Re: Identifying Date, Currency and Time variables

Posted in reply to bbrowne81

SAS only has 2 types of variables, num and char. That is, currencies, dates, times are all simply numeric. It's the format that dictates how they are output. So you would have to do some form of conditioning on either the format and/or the informat columns to achieve your desired results.

You could create some additionnal variable like

...

type,

format,

(case

when type="char" then "string"

when type="num" and format in ("DATE9.", "MONYY.", "DDMMYY8.") then "date"

when type="num" and format in (<some currency format list>) then "currency"

else "numeric"

end

) as derived_type

the issue is that of creating an exhaustive list that will cover all the formats that you encounter on a regular basis.

Ask a Question
Discussion stats
  • 2 replies
  • 281 views
  • 0 likes
  • 3 in conversation