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.

 

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 6 replies
  • 9270 views
  • 3 likes
  • 5 in conversation