BookmarkSubscribeRSS Feed
JohnChen_TW
Quartz | Level 8

As far as I know, all items and attributes for features in dataset would be automatically saved in SASHELP.

And I need to use PUT function to create a new variable in the macro. So, I tried to retrieve the variable format (e.g. $SEXOF6.) from SASHELP but it just recorded the char part as "$SEXOF.". Why?

 

Does anyone have a suggestion to retrieve the complete format?

 

 

 

6 REPLIES 6
Kurt_Bremser
Super User

It depends on how you applied the format to the variable.

proc format library=work;
value $mysex
  'M' = 'Male'
  'F' = 'Female'
;
run;

data class;
set sashelp.class;
format sex $mysex6.;
run;

proc sql;
/*create table test as*/
select name, format from dictionary.columns
where libname = 'WORK' and memname = 'CLASS';
quit;

data class1;
set sashelp.class;
format sex $mysex.;
run;

proc sql;
/*create table test as*/
select name, format from dictionary.columns
where libname = 'WORK' and memname = 'CLASS1';
quit;

Look at the result:

Column Name                       Column Format
-----------------------------------------------------------------------------------
Name                                                                               
Sex                               $MYSEX6.                                         
Age                                                                                
Height                                                                             
Weight                                                                             

Column Name                       Column Format
-----------------------------------------------------------------------------------
Name                                                                               
Sex                               $MYSEX.                                          
Age                                                                                
Height                                                                             
Weight                                                                             
RW9
Diamond | Level 26 RW9
Diamond | Level 26

We have no way of telling from what you have posted.  Post test data in the form of a datastep! If you have some code post that, and post what you want out at the end.  Sashelp.vcolumn -> Format should contain the format name and length, so how did you define the format as thats not a SAS format.

Reeza
Super User

What do you mean by retrieve the complete format? Are you looking for the format definition (ie proc format mapping) or something else? 

JohnChen_TW
Quartz | Level 8
My question is, I cannot know the format of each variable from the external files in advance.
After googled, I just know that the format will be saved in sashelp.columns. But it will not save the format with the number when the actual format is $SEXOF6..

1. What does the number of formats mean?
2. How to get the complete format from the external files in advance?
Kurt_Bremser
Super User

The metadata for external files are NOT to be found in sashelp.vcolumn or dictionary.columns. Those only deal with SAS datasets in currently assigned libraries. sashelp.column (note the missing v) is a static table supplied at SAS installation time that has nothing to do with current metadata.

 

What do you mean by "number of formats"? I can't find such a variable anywhere.

 

For your question 2, the formats for external files have to be determined by you from the documentation that accompanies such files. External files without documentation are worthless and should be returned to sender.

 

For how formats are stored in dictionary.columns (sashelp.vcolumn is just a view to that), see my earlier post.

RW9
Diamond | Level 26 RW9
Diamond | Level 26

There is several parts to your question here.  Firstly, for external files you cannot use SAS metadata libraries, that is only for files which appear in assigned libnames.  For external files you should have a data transfer specification which details all the structure of the file.  If you do not have this then you will be guessing and it is a bad import process.

 

Secondly formats are:

<type><name><length>

Where type is $ for character and missing for numeric.

Name is the name of the format.

Length is the maximum length in characters of the format.

So $SEXOF6

Means it is character, called SEXOF, and has a maximum length of 6 characters.

 

Now Where do you get the information that there is a format $SEXOF6?  If you can provide complete information -what type of files (examples?) documentation etc. as we are just huessing what your trying to do here.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 6 replies
  • 1604 views
  • 0 likes
  • 4 in conversation