BookmarkSubscribeRSS Feed
G_I_Jeff
Obsidian | Level 7

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;

5 REPLIES 5
PaigeMiller
Diamond | Level 26

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

--
Paige Miller
G_I_Jeff
Obsidian | Level 7

Good point, but how do I format the dates inside CATS and I still need double quotes around the entire built variable.

maguiremq
SAS Super FREQ

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" 
G_I_Jeff
Obsidian | Level 7

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;                                                               
PaigeMiller
Diamond | Level 26

@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 

--
Paige Miller

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 5 replies
  • 581 views
  • 3 likes
  • 3 in conversation