BookmarkSubscribeRSS Feed
bbrowne81
Calcite | Level 5

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!

2 REPLIES 2
Scott_Mitchell
Quartz | Level 8

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

Vince28_Statcan
Quartz | Level 8

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.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 883 views
  • 0 likes
  • 3 in conversation