07-05-2011 01:35 PM
I have two variables I'd like to concatenate (year, quarter) but using "||" to concatenate the variables leaves a whole bunch of spaces in the created variable. I am looking to create a year-quarter identifier without the spaces in the new variable. I would like to create a year-quarter variable like: 00:1 but I am having some trouble.
Here is what I was trying to do to get that variable:
In the log there is a line that says: "numeric values have been converted to character values at the places given by: 168:11 169:22.
The yr variable has missing observations and the year quarter variable has what looks to be a tab btwn the : and the quarter identifier.
Any help would be appreciated.
07-05-2011 01:58 PM
You can get rid of the spaces by enclosing the two variables within strip functions. e.g.,
Do you want a character or numeric variable? That answer is needed as well as an answer to how you want to deal with missing values.
07-05-2011 04:33 PM
The conversion message means SAS is expecting a character variable but you've supplied a numeric variable instead. SAS tries to be helpful and has done automatic type conversion to the best of its abilities, but it may not be what you want. In general, it is dangerous coding practice to rely upon automatic type conversion.
I can't tell which statement is giving you the conversion message, and I don't know the types of your variables.
1) If yr and qtr are both numeric, use this: date = compress( put(yr,4.) || ':' || put(qtr,1.) ); the compress call is defensive programming.
2) If yr is character and qtr is numeric, date = compress( yr || ':' || put(qtr,1.) );
In either case, you'd want to control the length of the date variable by "length date $ 6;" somewhere in the data step.
07-11-2011 10:10 AM
I think that you should use the CATS() function.
Without producing messages it will concatenate numeric and character variables after it trims leading and trailing blanks.
Since your numeric needs to be in a date format, you might need to use the vvalue() function or put() to ensure your chosen format is used, rather than the 12. format normally used by SAS when converting numeric variables to handle as strings.