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

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

1 ACCEPTED SOLUTION

Accepted Solutions
CTorres
Quartz | Level 8

proc datasets library=yourlib nolist;

  modify your_dataset;

  format your_var best7.;

quit;

CTorres

View solution in original post

17 REPLIES 17
CTorres
Quartz | Level 8

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

CTorres

robertrao
Quartz | Level 8

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;

CTorres
Quartz | Level 8

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

MaikH_Schutze
Quartz | Level 8

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.

naveen_srini
Quartz | Level 8

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

Reeza
Super User

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.

robertrao
Quartz | Level 8

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.

Reeza
Super User

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;

robertrao
Quartz | Level 8

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

Reeza
Super User

Proc contents or proc datasets?

robertrao
Quartz | Level 8

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;

Reeza
Super User

Please post your output from the following proc datasets code:

The output should be in the log.

proc datasets library=teams;

run;quit;

robertrao
Quartz | Level 8

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

Reeza
Super User

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;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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