BookmarkSubscribeRSS Feed
Tithi
Calcite | Level 5

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. 

8 REPLIES 8
yabwon
Onyx | Level 15

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

 

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



Tom
Super User Tom
Super User

@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.

ballardw
Super User

@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.

Tithi
Calcite | Level 5

I added the length statement but for some reason but QUOTE function is still not working. 

yabwon
Onyx | Level 15

Show us the log...

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



Tithi
Calcite | Level 5

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

andreas_lds
Jade | Level 19

Interesting. You need to post the complete log containing the code that ran, actually.

Why do you want to include quotes in the values?

Tom
Super User Tom
Super User

@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-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
  • 533 views
  • 1 like
  • 5 in conversation