- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hello
Let's say that I have a char column with format.
I know that using the sentance FORMAT VAR_NAME will remove the format from the column and the column type will remain same (IF it was char then will stay char and if was numeric then will stay numeric).
My question:
What is the way to remove format via proc sql?
I know to use input(Var_NAME,best.) and it remove the format and also convert it to numeric .
But I just want to remove the format (via proc sql) without change the field type.
What is the way to do it please?
Data t1;
input City $;
cards;
222
333
444
;
Run;
proc format ;
value $fmt
'222'='London'
'333'='Liverpool'
'444'='Leeds'
;
Run;
Data t2;
set t1;
format City $Fmt.;
Run;
Data want1a;
set t2;
format City;/**Remove format from column City: The field stay char**/
Run;
proc sql;
create table want1b as
select input(city,best.) as city /***Remove the format and create numeric field**/
from t2
;
quit;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Using the put function should work. But if you just want to remove a format, using proc datasets is recommended.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
If you want to just show your three-digit codes, remove the format with PROC DATASETS and be done with it.
A numeric variable eats 8 bytes, while you can store the codes in a $ 3 variable. And you will never make calculations with the codes.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thanks, so as far as I understand via proc sql we cannot remove format?(without change column type)
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
PROC DATASETS only changes the header page of a dataset, while PROC SQL needs to rewrite the whole dataset.
That's why PROC DATASETS is the right tool (Maxim 14).
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
There is no direct syntax in PROC SQL to do what you can with the FORMAT statement in a data step or proc datasets.
You cannot just select it AS something else. PROC SQL remembers the format attached. But if you do some operation on the variable (hopefully something that does not actually change the value) then PROC SQL will "forget" the format (and LABEL and other attributes).
Example:
data have;
set sashelp.class ;
format age 4. ;
run;
proc sql ;
create table want as
select *, age as New_age1, sum(age,.) as New_age2
from have
;
quit;
proc contents data=want varnum;
run;