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?
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
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.
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;
This value
20 - < -10 ='-(10-20)'
is shwon as -10 in csv
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.
Not sure.
20 - < -10 ='"09"x -(10-20)' ?
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.
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)
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.
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.