BookmarkSubscribeRSS Feed
SASPhile
Quartz | Level 8

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?

8 REPLIES 8
Jagadishkatam
Amethyst | Level 16

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
SASPhile
Quartz | Level 8

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.

Jagadishkatam
Amethyst | Level 16

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
SASPhile
Quartz | Level 8

This value

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

is shwon as -10 in csv

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

Ksharp
Super User

Not sure.

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

Reeza
Super User

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.

Kurt_Bremser
Super User

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)

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 8 replies
  • 1159 views
  • 1 like
  • 6 in conversation