data _null_;
call execute ("proc format;");
call execute ("value $parm");
call execute ("'SPQTCFS' = 'Supine QTcF - Fridericia's#Correction Formula (msec)'");
call execute ("'SPHRMS' = 'Supine Summary (mean) Heart Rate#(beats/min)';") ;
run;
Dear All,
How to define a format with single quote?
E.g. In following case -
call execute ("value $parm");
call execute ("'SPQTCFS' = 'Supine QTcF - Fridericia's Correction Formula (msec)'");
call execute ("'SPHRMS' = 'Supine Summary (mean) Heart Rate#(beats/min)';")
I have to create a format for the given test code. But due to single quote I am not able to do it. I have tried using quoting functions but couldn't helped.
In other case, I replaced Single quote with * in order to create the format but at the end I am expecting my label values to be displayed with Quote.
Any solution on this! (SAS 9.4)
If it is not clear enough let me know will provide some more details.
Cheers!
PankP
Just concatenate it, e.g:
call execute(cat("'spqtcfs'='Supince QTcF - Fridericia","'","s correction fomula"));
Is there a reason why you are using call execute here at all? I don't see any reason for it?
@RW9 wrote:
Just concatenate it, e.g:
call execute(cat("'spqtcfs'='Supince QTcF - Fridericia","'","s correction fomula"));Is there a reason why you are using call execute here at all? I don't see any reason for it?
That doesn't look right. With that the code that CALL EXECUTE() sends will now be missing the ending single quote for the second string. Although SAS might let it execute since SAS does still sometimes allow you to omit quotes from around strings in VALUE statements.
Your probably right Tom, to be honest I didn't look to far into the actual code, just wanted to present concatenating the various parts. It seems very odd to me that a proc format is being generated in this way, considering if this comes from a file, you could read it into a datastep and then cntlin that rather than faffing about with generating the code, and if its an include, then just include the proc format. It all just seems a bit pointless.
There's a minor omission in our program. It probably is not the source of the problem, but you should add:
call execute('run;');
Your code looks fine. If it's just plain not working, reverse the single and double quotes, and use two single quotes for the apostrophe:
call execute ('"SPQTCFS" = "Supine QTcF - Fridericia''s#Correction Formula (msec)"');
Make sure you are generating valid SAS code. If the content of a quoted string contains the character used to quote it then you need to double that character. Or else you need to change to using the other type of quote on the outside.
Your program is generating this line of code to pass to SAS via CALL EXECUTE()
'SPQTCFS' = 'Supine QTcF - Fridericia's#Correction Formula (msec)'
It should be generating either
'SPQTCFS' = 'Supine QTcF - Fridericia''s#Correction Formula (msec)'
or
'SPQTCFS' = "Supine QTcF - Fridericia's#Correction Formula (msec)"
So change your code to this:
call execute ("'SPQTCFS' = 'Supine QTcF - Fridericia''s#Correction Formula (msec)'");
PROC FORMAT supports creating a format from a data set using CNTLIN. You need to create a data set in a specific format but it's usually simpler.
data my_fmt;
infile cards dlm="," dsd;
fmtname="parm";
type="C";
length label $50.;
input start $ label $;
cards;
SPQTCFS, "Supine QTcF - Fridericia's#Correction Formula (msec)"
SPHRMS, "Supine Summary (mean) Heart Rate#(beats/min)"
;;;;
run;
proc format cntlin=my_fmt;run;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.