BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Oernfeldt
Calcite | Level 5

Dear all, 

I am new to SAS but advanced in STATA. I have a variable called hfaudd (highest accomplished education) which I would like to formate to a better (esier to interpret) variable with Primary school, Upper secondary school, higher education and Post graduate. The variabel is confusing build up, where it goes from 1-9914 with each education being a differnt number.

I got a piece of code from a collegue: Newvar = put(hfaudd, $AUDD2010-LIL5-K.), which for me look like SAS. Can anyone tell me what "$AUDD2010-LIL5-K" is supossed to do? or maybe the hole thing in a contekts? 

I know AUDD is a register, but do not know about LIL. 

 

Then if i am lucky I could start seeing a pattern in the variable and might even be able to solve the problem in STATA. 

 

Best Mads Ø

1 ACCEPTED SOLUTION

Accepted Solutions
Panagiotis
SAS Employee

Looks like it's a custom format for your specific use case. So someone most likely created it.

 

For example.

 

I have this data for my business

 

Column

1

2

1

1

3

 

That doesn't mean much. I am creating a custom format to make this more meaningful.

 

My custom format is named businesstype, and will format those numbers to the following:

1 = Local

2 = Global

3 = Unknown

 

Now I can apply that custom format I created into a new column.

 

So I would use:

newColumn = put(column, $businesstype.)

 

 

New table will look like this:

 

Column   NewColumn

1              Local

2             Global

1             Local

1             Local

3             Unknown

 

 

The $ sign in front of the format indicates it's character. The put function returns a value using a specified format.

 

PUT Function

 

Format PROC

 

Run this program. It'll create a format and a table, then apply that format to create a new column. At the end it has code how to see what your format does. Looks like your original column is probably character since the format uses a $ sign.

 

You will have to adjust the format proc to find where you format is if you want to see what it does.

/*create custom format*/
proc format;
	value $businesstype 
		'1' = 'Local'
		'2' = 'Global'
		'3' = 'Unknown';
run;

/*create fake table*/
data test;
	infile datalines;
	input Column :$4.;
	datalines;
1
2
1
1
3
;
run;

/*apply format*/
data newtable;
	set test;
	NewColumn=put(column,$businesstype.);
run;


/*view what the format does*/
proc format fmtlib lib=work; /*lib= points to the library the format is in. Mine is in work, not sure where yours is.*/
	select $businesstype; /*select the format to view*/
run;

 

 

 

 

- Peter

View solution in original post

5 REPLIES 5
Panagiotis
SAS Employee

Looks like it's a custom format for your specific use case. So someone most likely created it.

 

For example.

 

I have this data for my business

 

Column

1

2

1

1

3

 

That doesn't mean much. I am creating a custom format to make this more meaningful.

 

My custom format is named businesstype, and will format those numbers to the following:

1 = Local

2 = Global

3 = Unknown

 

Now I can apply that custom format I created into a new column.

 

So I would use:

newColumn = put(column, $businesstype.)

 

 

New table will look like this:

 

Column   NewColumn

1              Local

2             Global

1             Local

1             Local

3             Unknown

 

 

The $ sign in front of the format indicates it's character. The put function returns a value using a specified format.

 

PUT Function

 

Format PROC

 

Run this program. It'll create a format and a table, then apply that format to create a new column. At the end it has code how to see what your format does. Looks like your original column is probably character since the format uses a $ sign.

 

You will have to adjust the format proc to find where you format is if you want to see what it does.

/*create custom format*/
proc format;
	value $businesstype 
		'1' = 'Local'
		'2' = 'Global'
		'3' = 'Unknown';
run;

/*create fake table*/
data test;
	infile datalines;
	input Column :$4.;
	datalines;
1
2
1
1
3
;
run;

/*apply format*/
data newtable;
	set test;
	NewColumn=put(column,$businesstype.);
run;


/*view what the format does*/
proc format fmtlib lib=work; /*lib= points to the library the format is in. Mine is in work, not sure where yours is.*/
	select $businesstype; /*select the format to view*/
run;

 

 

 

 

- Peter

Oernfeldt
Calcite | Level 5

Thank you very must for the quick answer! I will look in to it. 

Best Mads

Panagiotis
SAS Employee

No problem!

 

 

- Peter

mkeintz
PROC Star

However, the use of dashes in the name of the format  ($AUDD2019-LIL5-K) is not permitted in SAS.   So I would be very interested to know how this was successfully used in a sas program.

--------------------------
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

--------------------------
Panagiotis
SAS Employee

I noticed that as well. I figured maybe the creator knows of a workaround that I am not familiar with? I'd love to know how they did too.

 

 

- Peter