DATA Step, Macro, Functions and more

Proc format and export

Reply
Super Contributor
Posts: 647

Proc format and export

I created a user defined format using proc format.

afetr applying the format a variable and later when exporting the dataset I'm not seeing the values in format there.

TThe values of the variable after applying the format look loke theese

(10-20)

-(20-40)

after exporying i see -10 and 20 etc.

how to export without any data loss?

Trusted Advisor
Posts: 1,131

Re: Proc format and export

could you please let me know how you applied the format , either by format statement or via put function. I believe the issue what you mentioned arises when the format is applied by format statement.

Please try to apply the format by put function to resolve the issue.

Thanks,

Jag

Thanks,
Jag
Super Contributor
Posts: 647

Re: Proc format and export

I defined as follows:

proc format;

value diff;

10-20='10-20'

-10-20='(10-20)';

run;

data t;

set y;

score format diff.;

run;

so when i export dataset, score doesn't show up as whats defined or displayed in the dataset. instead score shows as -10 and 10 etc.

Trusted Advisor
Posts: 1,131

Re: Proc format and export

Please try to use put function as

Also i guess you have applied the format as

format score diff.;

Now change this to

data t;

set y(rename=(score=score2));

score=put(score2,diff.);

run;

Thanks,
Jag
Super Contributor
Posts: 647

Re: Proc format and export

This value

20 - < -10   ='-(10-20)'

is shwon as -10 in csv

Super User
Super User
Posts: 7,417

Re: Proc format and export

Just to check, do you really mean it looks like that as CSV, i.e. have you opened the file in notepad and looked at the data.  I would suggest you are opening the CSV in Excel, which is resolving the equation.

Super User
Posts: 9,687

Re: Proc format and export

Not sure.

20 - < -10   ='"09"x -(10-20)'   ?

Super User
Posts: 17,912

Re: Proc format and export

To expand, if you export to Excel SAS does not use the formats in the export. There's usually a note in the log to that effect.

Instead of applying the format using a format statement you'll need to create a new variable and recode it using the put function as indicated by

Your code has some issues though as your ranges overlap so I'd expect SAS to complain about that, as well as having incorrect format statement.

Super User
Posts: 6,964

Re: Proc format and export

Once you have assigned a format to a variable, the put statement will honor that when outputting to a text file.

Use .csv as the transfer format, as it is easily controllable with a simple text editor.

-> Textuality rules!

(common UNIX adage)

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Ask a Question
Discussion stats
  • 8 replies
  • 335 views
  • 1 like
  • 6 in conversation