BookmarkSubscribeRSS Feed
deleted_user
Not applicable
In a stored process, in a PROC SQL statement, I want to concatenate a value to a numeric field, such as "001" || WOMBAT as ALPHAWOMBAT.

Is this possible? Or, does something have to be done to the numeric field prior to concatenation? Does anyone have a small sample of what they did to be able to do a concatenation of this kind?
2 REPLIES 2
Cynthia_sas
SAS Super FREQ
Hi!
Not entirely sure what you want to do since your subject says concat a numeric "field" to a parameter value but down in your explanation, you say you want to concat a value to a numeric field.

Let's say that I have a parameter called "parm" coming from the stored process and I want to concat a number to it. Try this code and see if this is what you were thinking of.
[pre]
%let parm=WOMBAT;

proc sql;
create table work.testit as
select name, age, height,
"001"||"&parm" as alphawombat
from sashelp.class;
run;
quit;

proc print data=work.testit;
run;
[/pre]

it produces this (partial) output: [pre]

Obs Name Age Height alphawombat
1 Alfred 14 69.0 001WOMBAT
2 Alice 13 56.5 001WOMBAT
3 Barbara 13 65.3 001WOMBAT
4 Carol 14 62.8 001WOMBAT
5 Henry 14 63.5 001WOMBAT
6 James 12 57.3 001WOMBAT
[/pre]
or did you mean that you wanted to concat a number from a parm to a second parm to make a new macro variable???? In which case, concatenation works a bit differently. Consider that I still have a parameter whose value is WOMBAT and I have another parameter whose value is 001:
[pre]
** here I concatenate them in %LET stmts.;
** look in the LOG to see how they work;
** submit them in an EG code node after you submit the above code;
%let parm=WOMBAT;
%let num = 001;
%let macvar = &num&parm;
%let macvar2 = &parm.#
%put -------> concat macro vars;
%put macvar = &macvar;
%put macvar2 = &macvar2;

** now I want to use them in a where clause;
** Must have quotes around them when their usage in the where stmt;
** makes quotes necessary.;
options symbolgen mprint;
proc print data=testit;
where alphawombat in ("&macvar", "&macvar2");
run;

[/pre]

MPRINT and SYMBOLGEN are very useful options because they can help you debug what the macro processor is doing with macro variables when they're referenced in your code.

cynthia
deleted_user
Not applicable
Thanks for the info! I'll put it to good use.

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
  • 2 replies
  • 753 views
  • 0 likes
  • 2 in conversation