I need to create a record header containing static data and defined variables. This header needs to be wrapped in quotes:
"CSR+nnnnnnnnnnnnnn012cccccccccccc"
The CSR+ is static defined data.
The first eight and second eight following numerics are dates (yyyymmdd) from defined variables.
The 012 is static defined data.
The last twelve character data is another defined variable.
When I try to create the variable without the wrapped double quotes, I'm getting invalid numeric data on the 'CSR+'. I assume it's due to the + sign?
header='CSR+'+date1+date2+'012'+character_var;
You can't use + for character strings, because SAS thinks + is addition of numeric variables.
What you want is the CATS function. See the example at https://documentation.sas.com/doc/en/pgmmvacdc/9.4/lefunctionsref/n1e21rr6al5m2nn19r1fat5qxwrt.htm
Good point, but how do I format the dates inside CATS and I still need double quotes around the entire built variable.
Use PUT with whatever date format that you need. We don't have a reproducible example to go off of, so it's difficult for us to get you on the right path. Here's one that I came up with:
data have;
input id $1. date :mmddyy10.;
datalines;
A 10/18/2021
;
run;
data want;
set have;
want = quote(cats(id, put(date, mmddyy10.)));
run;
Have produces this:
Obs id date 1 A 22571
Want produces this:
Obs id date want 1 A 22571 "A10/18/2021"
Okay, this is getting me pretty close. But I have 3 double quotes around the header variable and I'm just not seeing what I need to change:
data _null_; file TAPE dsd; set user.nfctape; null=''; rc='1'; rc5='5'; csr='CSR'; sysid='SYSTEMID'; acntcd='ACCOUNTCODE'; rate='ZRMM@@12'; hlq1='DSNACCOUNTCODE1'; strt='Start_date'; stop='Stop_date'; time='00:00:00'; x=012; if size=0 then delete; if account='' then account='nfcunknown'; if account=. then account='nfcunknown'; size=size*.001**3; header=quote(cats(csr, put(start_date, yymmddn8.), put(end_date, yymmddn8.), x, account)); put header ident start_date end_date time time rc rc5 sysid system acntcd account strt start_date hlq1 hlq stop end_date rc rate size; run;
@G_I_Jeff wrote:
Good point, but how do I format the dates inside CATS and I still need double quotes around the entire built variable.
No you do NOT need quotes around the entire variable, CATS produces only character strings.
You format dates the same way you would format any date at all, and as shown by @maguiremq
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.