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

Has anyone had this scenario and found a fix.  I have a variable named age coming in from a dataset which has format=4. 

I have a proc sql which creates a new dataset and selects this variable.  In this instance the format is copied across.  Now when a variable is processed in SQL, and no format is applied to the outgoing variable, then the format is missing.  Here is an example:

data have;
  attrib age format=4. length=8;
  age=10;
run;

proc sql;
  create table want as
  select age,
         sum(age,0) as want_age
  from   have;
quit;

If you run this you will see age retains the 4. format, but want_age does not have the 4. format applied.  I am after the syntax to remove format when I am not processing the variable - as summing 0 in this case should be ok, but would like to avoid processing.  Have tried:

create table want (format _all_)...
age format=,

Just can't seem to put my finger on the right syntax (if indeed there is one).  I am aware that in datastep you can do format _all_, or proc datasets, but the question is can I do it in my existing proc sql step without needing a further step, or is fooling the compiler into creating a new variable the only way?

1 ACCEPTED SOLUTION

Accepted Solutions
andreas_lds
Jade | Level 19

There seems to be no way to remove a format with proc sql ,except the one you already found.

View solution in original post

6 REPLIES 6
andreas_lds
Jade | Level 19

There seems to be no way to remove a format with proc sql ,except the one you already found.

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Ok, thanks.  I had thought that might be the case.  Its a tad annoying to have to resort to a function call or some logic to avoid, but I suppose its an optional component of the language, not really a SAS part.

Ksharp
Super User

SQL can modify format,But I don't know if it is what you are looking for.

 


proc sql;
  create table want as
  select age,
         sum(age,0) as want_age
  from   have;
  alter table want
   modify age format=best32. ;
quit;
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Thanks.  Its not what I am after though, I would like to remove a format completely, without an additional step.

Tom
Super User Tom
Super User

Post it as a new feature request.

FreelanceReinh
Jade | Level 19

Good question.

 

Slightly shorter:

 

select age+0 as age

(as was suggested by Tom in this 2015 thread: SAS sql remove format and by Howard Schreier -- author of the book "PROC SQL by Example" -- in a 2007 discussion on SAS-L: Remove a format via proc sql, where he also suggested trim(varname) as varname for character variables). Others suggested assigning a "neutral" format such as BEST. or $F. in these old discussions.

 

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 10882 views
  • 3 likes
  • 5 in conversation