BookmarkSubscribeRSS Feed
kateb409
Obsidian | Level 7

Hi there,

I am currently stuck on a homework question about creating formats using an external control file. I am working in SAS Studio for SAS OnDemand. The SAS version is 9.4_M6 and operating on the Linux X64 environment. 

Here is the question and I have also attached the file mentioned in the question:

 

 

I realize that I could use the 'proc format' statement instead, but I would like to learn how to accomplish it using the external control file method. 

I think I am missing some information regarding how to set up an external control file and how to develop the syntax to use it to create formats. 

If anyone can help me, please let me know. Thank you!

 

Sincerely,

 

Kaitlin E Buck

4 REPLIES 4
mkeintz
PROC Star

This homework is offering you the choice to use  the CNTLIN= option in proc format.  Starting from the Summary of Optional Arguments documentation page for proc format, click on the CNTLIN=input-control-SAS-data-set link. 

 

Drill down further (to Input Control Data Set).  You can write a SAS dta step to read in the Study Formats sheet in your workbook to create a sas dataset with variables such as FMTNAME,  START, END, LABEL, MIN, MAX, LENGTH HLO, and others described in the documentation.

 

The last link above includes the following text (bold italics mine).

 

You specify an input control data set with the CNTLIN= option in the PROC FORMAT statement. The FORMAT procedure uses the data in the input control data set to construct informats and formats. Thus, you can create informats and formats without writing INVALUE, PICTURE, or VALUE statements.

 

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
ballardw
Super User

Either approach will use proc format, one uses a data set as input using the Cntlin option.

 

The Cntlin data set requires specific variables to work. One of the easiest ways to determine what that data set look like is to create a couple of small formats using value statements and then use the option on the Proc Format statement to create an output data set with the Cntlout=<data set name>. Or use the example value statements for the entire example and use the Cntlout option.

 

The key elements that you must provide are a 1) the format name 2) the Start value (original value) 3) the label (the formatted value for the start value and 4) the type, numeric or character. If you have a range of values then you need an End value to indicate the upper value. If you are using ranges with excluded endpoints I recommend creating a small example and examining a cntlout data set as you need to set a couple more variables.

Reeza
Super User

You create a file with the old values, new values/ranges and the format names. 

Then you import the file into SAS and add some details to the dataset needed for SAS to understand. 

This means that variables need specific names (format name, format type, start, end, label, hlo) are the typical ones you'll want to pay attention to. 

 

The documentation has a good example here that's pretty detailed and your formats are pretty straightforward, the hlo usage is the most complicated thing you'll need to account for in your code. 

https://documentation.sas.com/?cdcId=pgmsascdc&cdcVersion=9.4_3.5&docsetId=proc&docsetTarget=n1e19y6...

 

FYI - you can use CNTLOUT to get your formats back out of a proc if you never need it as well. I sometimes use this trick to see how I need to structure my CNTLIN data sets so I create the format using PROC FORMAT, pipe it back out to a data set and see how it's formatted and which variables I need to specify and how. 

 

proc format;
value age_group
low - 13 = 'Pre-Teen'
13 - 16 = 'Teen'
16 - high = 'Adult';

value $ gender_fmt
'M' = 'Male'
'F' = 'Female'
other = 'Other';
run;

proc format cntlout=check_format_table;
run;

proc print data=check_format_Table;
var fmtname type start end label hlo sexcl eexcl;
run; 

@kateb409 wrote:

Hi there,

I am currently stuck on a homework question about creating formats using an external control file. I am working in SAS Studio for SAS OnDemand. The SAS version is 9.4_M6 and operating on the Linux X64 environment. 

Here is the question and I have also attached the file mentioned in the question:

"Task:  The ‘Data Map - Hypertension Study.xlsx’ file contains a worksheet named ‘Study Formats’.  Use the specifications found there to create the following:

 

In the ‘HypTabs’ library, a catalog named ‘HypFormats’ which contains the 11 formats (7 numeric and 4 character) per the Data Map specifications.

 

You may accomplish this using either:

  • A PROC FORMAT statement with 11 VALUE statements, or
  • Build a control file with the required variables

 

In Box ‘A’ below, copy-and-paste the output from PROC CATALOG to show that all 11 formats were created and are stored in the ‘HypTabs.HypFormats’ catalog.

Box ‘B’ (below) is to contain the details used to create each format.  Copy-and-paste either:

  1. The PROC FORMAT SAS code used to create the 11 formats (i.e. containing all 11 VALUE statement if they were used to create the formats), or

The contents of the control file (e.g. Excel worksheet) used to generated the 11 formats using the CNTLIN= option."

 

I realize that I could use the 'proc format' statement instead, but I would like to learn how to accomplish it using the external control file method. 

I think I am missing some information regarding how to set up an external control file and how to develop the syntax to use it to create formats. 

If anyone can help me, please let me know. Thank you!

 

Sincerely,

 

Kaitlin E Buck


 

kateb409
Obsidian | Level 7

Hi @Reeza, thank you for this explanation. I like how you actually gave me an example to visualize it. I think I did not understand the very basic fundamentals of it, so I had my professor explain it a little more in class yesterday, so now I'll have to play around with it myself to what works and what doesn't.

Thank you!

 

Sincerely,

 

Kaitlin E Buck

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 4 replies
  • 1007 views
  • 2 likes
  • 4 in conversation