DATA Step, Macro, Functions and more

Problem with PROC FORMAT PICTURE statement

Accepted Solution Solved
Reply
Contributor
Posts: 26
Accepted Solution

Problem with PROC FORMAT PICTURE statement

[ Edited ]

Hi all,

 

I'm using SAS Studio from SAS onDemand for Academics and I'm running into problems with directives from the PICTURE statement. Suppose I wish to display the year in my output:

 

proc format;
picture dnt
other='%Y        ' (datatype=datetime);
run;
data tmp;
input date_time datetime21.;
format date_time dnt.;
cards;
12mar2016 11:05:00 pm
;
run;
proc print;
run; 

 

If you compile this program it will successfully run with the output "2016". Now, let's say for some reason I change my mind and I want to display the month instead, all I do is to modify the directive as follows:

 

proc format;
picture dnt
other='%B        ' (datatype=datetime);
run;
data tmp;
input date_time datetime21.;
format date_time dnt.;
cards;
12mar2016 11:05:00 pm
;
run;
proc print;
run;

 

However, if you run the code above the output will NOT be automatically updated to "March". I tried everything I could to solve this problem and the only way I found was to reset the entire SAS session which is quite annoying. Is this a bug or is there any workaround to fix this issue?

 

Thanks a lot!


Accepted Solutions
Solution
‎03-13-2016 01:21 PM
Super User
Posts: 17,831

Re: Problem with PROC FORMAT PICTURE statement

What do you mean the results are not automatically update? 

Also consider explicitly referencing the data in your proc prints. It's not required but helps avoid errors. 

What happens if you use a diff format name?

 

If the error persists Please post your log. 

View solution in original post


All Replies
Solution
‎03-13-2016 01:21 PM
Super User
Posts: 17,831

Re: Problem with PROC FORMAT PICTURE statement

What do you mean the results are not automatically update? 

Also consider explicitly referencing the data in your proc prints. It's not required but helps avoid errors. 

What happens if you use a diff format name?

 

If the error persists Please post your log. 

Contributor
Posts: 26

Re: Problem with PROC FORMAT PICTURE statement

[ Edited ]

Thank you very much Reeza! Smiley Happy I guess whenever I use a PROC FORMAT the format(s) I choose are somehow "inscribed" into SAS's internal memory and "bound" to directives associated with it, meaning whenever I wish to pick a different directive I also have to use a different format as well. 

Contributor
Posts: 26

Re: Problem with PROC FORMAT PICTURE statement

Actually Reeza, today I tried my code again and made some minor modifications. It turns out that one way to fix this issue is to place the FORMAT statement in the PRINT procedure rather than the DATA step. Not sure about the reason for this and hope you could explain why? Thank you.

Super User
Posts: 17,831

Re: Problem with PROC FORMAT PICTURE statement

Your original issue was incorrect, the new proc format should have overwritten the old one. 

 

I think ink the proc print without data set pointers is th issue. 

 

I'll try and test it tomorrow unless someone else has. 

Super User
Posts: 17,831

Re: Problem with PROC FORMAT PICTURE statement

[ Edited ]

I tested and CANNOT replicate your issue.

If you can replicate the issue, then I highly suggest that you report it to SAS tech support.

 

In fact, all you have to do is change the definition, you don't even have to re-read the dataset or reapply the format.

 

ods pdf file='C:\_localdata\output1.pdf' startpage=never;
proc format;
picture dnt
other='%Y        ' (datatype=datetime);
run;
data tmp;
input date_time datetime21.;
format date_time dnt.;
cards;
12mar2016 11:05:00 pm
;
run;
proc print data=tmp;
run; 

proc format;
picture dnt
other='%B        ' (datatype=datetime);
run;

proc print data=tmp;
run;
ods pdf close;

 

delete diff format.JPG

 

Contributor
Posts: 26

Re: Problem with PROC FORMAT PICTURE statement

I actually contacted the tech support team and it really turns out to be a defect which is only present in SAS Studio. You are right about the workaround to fix this issue for the time being, which is to use another format. And by the way, you can ONLY replicate this issue in SAS University Edition or SAS onDemand for Academics, SAS Studio. Please see the problem note: http://support.sas.com/kb/57/730.html
☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 6 replies
  • 448 views
  • 3 likes
  • 2 in conversation