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 Ø
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.
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
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.
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
Thank you very must for the quick answer! I will look in to it.
Best Mads
No problem!
- Peter
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.
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
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.