I am trying to add quotes to my string variable but my QUOTE function is not lighting up blue.
My code here:
data want;
set have;
code3 = quote(code2);
put code3=;
run;
my code2 variable contains string ICD codes.
When you run:
data have;
input code2 $;
cards;
ABC
AB
A
;
run;
data want;
set have;
code3 = quote(code2);
put code3=;
run;
you will get:
code3="ABC " code3="AB " code3="A " NOTE: There were 3 observations read from the data set WORK.HAVE. NOTE: The data set WORK.WANT has 3 observations and 2 variables. NOTE: DATA statement used (Total process time): real time 0.02 seconds cpu time 0.01 seconds
in the log.
If you don't want spaces at the end, use STRIP() function:
data want;
set have;
code3 = quote(STRIP(code2));
put code3=;
run;
and you will get:
code3="ABC"
code3="AB"
code3="A"
in the log.
Bart
@yabwon wrote:
...
If you don't want spaces at the end, use STRIP() function:
...
If you don't want spaces at the end use the TRIM() function. The STRIP() function will also remove spaces from the beginning. Trailing spaces are not normally significant to SAS strings comparisons, but leading spaces are. Removing the leading spaces makes a significant change to the value being represented while removing just the trailing spaces does not.
@Tithi wrote:
I am trying to add quotes to my string variable but my QUOTE function is not lighting up blue.
My code here:
data want;
set have;code3 = quote(code2);
put code3=;
run;
my code2 variable contains string ICD codes.
A very large number of functions do not get highlighted. It can depend on your version of SAS, OS and if you are using the Display Manager (or "Base" SAS ) you can add custom highlights.
Best practice is to assign a length to new character variables. You can end up with odd truncated values because the first assignment can set the length, such as in your Code3= , of the variable and lead to odd results.
I added the length statement but for some reason but QUOTE function is still not working.
Show us the log...
code3=
code3=
code3=
code3=
code3=
code3=
code3=
code3=
code3=
NOTE: There were 73217 observations read from the data set WORK.ICDGROUP2.
NOTE: The data set WORK.ICDGROUP3 has 73217 observations and 8 variables.
NOTE: DATA statement used (Total process time):
real time 20.25 seconds
cpu time 7.82 seconds
Interesting. You need to post the complete log containing the code that ran, actually.
Why do you want to include quotes in the values?
@Tithi wrote:
I am trying to add quotes to my string variable but my QUOTE function is not lighting up blue.
My code here:
data want;
set have;code3 = quote(code2);
put code3=;
run;
my code2 variable contains string ICD codes.
Is your question really just about what colors the text editor is using to display your program?
Do not worry too much about what the text editor is doing. The important thing is whether your code WORKS or not.
Your code is valid. It will work as long as CODE3 is defined long enough to hold the longest values of CODE2 after it has add quotes added around it (and any embedded quotes doubled). Since you did not define CODE3 before the assignment statement SAS will default to defining it to have a length of 200 bytes.
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.