SAS FORMAT

Accepted Solution Solved
Reply
Super Contributor
Posts: 1,040
Accepted Solution

SAS FORMAT

Hi,

I have a SAS dataset in which the format on a particular variable is Best12.

I changed to Best7. and applied it.

When I close the dataset and reopen it the format is still Best12.

How can I save the changes before closing the dataset?????

Regards


Accepted Solutions
Solution
‎12-30-2014 12:11 PM
Regular Contributor
Posts: 180

Re: SAS FORMAT

proc datasets library=yourlib nolist;

  modify your_dataset;

  format your_var best7.;

quit;

CTorres

View solution in original post


All Replies
Regular Contributor
Posts: 180

Re: SAS FORMAT

You can use Proc DATASETS to permanently change the format of a variable. You do not need to open the dataset

CTorres

Super Contributor
Posts: 1,040

Re: SAS FORMAT

So IF I use the following code I can change the formats for variables in a dataset present in a particular library??????

Thanks

proc datasets library=sgflib;

modify dataset_name;

format price dollar6.2 ;

informat date mmddyy10.;

run;

Regular Contributor
Posts: 180

Re: SAS FORMAT

Yes. And also remember to end the proc Datasets with a quit; statement.

Contributor
Posts: 45

Re: SAS FORMAT

Hi Robert,

Could you share the code you used that didn't work for you. I am curious because you can definitely apply a format permanently using the DATA step. Although you have to create a new copy of the data set. Using a FORMAT statement inside of DATA step will assign the format permanently.

data new;

     set test;

     format numvar best7.;

run;

Thanks,

M.

Frequent Contributor
Posts: 115

Re: SAS FORMAT

Hi, I believe the reason why C.Torres suggested the use of proc datasets is because you can avoid datastep processing like in your example writing to a new dataset. You are pretty much compiling, executing and doing the whole process that is something can be avoided.

You can assign a format even with an attribute statement, nevertheless proc datasets is a powerful procedure for managing SAS datasets.

HTH,

Naveen

Grand Advisor
Posts: 17,389

Re: SAS FORMAT

I think the word "close the dataset" implies that opened the dataset in the viewer and modified the format there, which does not stick beyond the viewer session.

Super Contributor
Posts: 1,040

Re: SAS FORMAT

Hi,

Thank you all for the reply.

I get the following error can someone help me understand the meaning and the place of mistake????

I have the dataset teamA in the teams library

Thanks

proc datasets library=teams nolist;

  modify teamA;

  format VAR1 best8.;
  format var2 var3 var4 var5  best7.;

quit;

ERROR: The file teams.teamA (memtype=(DATA VIEW)) was not found, but appears on a MODIFYstatement.

Grand Advisor
Posts: 17,389

Re: SAS FORMAT

Exactly that, there's no dataset named teamA in your library teams.

Proc datasets requires both a run and quit.

What's the output from the following, does it list teamA?

proc datasets library=teams;

run; quit;

Super Contributor
Posts: 1,040

Re: SAS FORMAT

yes. it does list TeamA...after running Proc Contents

I was thinking we do not have permission to change the format on the datasets........and maybe that's the reason its giving that ERROR????

Do you agree???

Regards

Grand Advisor
Posts: 17,389

Re: SAS FORMAT

Proc contents or proc datasets?

Super Contributor
Posts: 1,040

Re: SAS FORMAT

I mean the error is with Proc Datasets..........

proc datasets library=teams nolist;

  modify teamA;

  format VAR1 best8.;
  format var2 var3 var4 var5  best7.;

run;

quit;

Grand Advisor
Posts: 17,389

Re: SAS FORMAT

Please post your output from the following proc datasets code:

The output should be in the log.

proc datasets library=teams;

run;quit;

Super Contributor
Posts: 1,040

Re: SAS FORMAT

This is all what I got in the log!!!

Apart from this there is a " results viewer " where I could see all the datasets in this library and TeamA exists there!!!!

2492  proc datasets library=teams;
2493
2494  run;

2494!      quit;

NOTE: PROCEDURE DATASETS used (Total process time):
      real time           0.17 seconds
      user cpu time       0.12 seconds
      system cpu time     0.00 seconds
      memory              529.06k
      OS Memory           26860.00k
      Timestamp           12/30/2014 04:42:49 PM
      Step Count                        142  Switch Count  0

Grand Advisor
Posts: 17,389

Re: SAS FORMAT

Proc datasets doesn't generate output to the results window, only the log, in SAS 9.3 at least.

If you're 100% sure it exists and the code below doesn't work, contact tech support.

proc datasets library=teams;

  modify teamA;

  format VAR1 best8. var2 var3 var4 var5  best7.;

run;

quit;

☑ This topic is SOLVED.

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

Discussion stats
  • 17 replies
  • 549 views
  • 6 likes
  • 5 in conversation