Hello. I would like to be able to cobble together a variable name by using parameters and the "concatenate" operator instead of writing multiple if-then-else statements. For example, the following code block for a calculated item returns the appropriate variable based on the input parameters:
IF ( ( 'ATD Cohort Year'p = '2012' ) AND ( 'End Term'p = '201214' ) )
RETURN 'ATD_2012_2014'n
ELSE IF ( ( 'ATD Cohort Year'p = '2012' ) AND ( 'End Term'p = '201216' ) )
RETURN 'ATD_2012_2016'n
ELSE ' '
There are many, many combinations of 'ATD Cohort Year' and 'End Term' and I will need to write if-then-else statements for each combination. Instead, I would like to do something like the following code blocks where only one if-then-else statement is required.
This code block returns the string: ATD_201212_201214. This is the name of the column I want to return in my data when someone enters 2012 for cohort year and 201214 for end term.
IF ( ( 'ATD Cohort Year'p NotMissing ) AND ( 'End Term'p NotMissing ) )
RETURN Concatenate(Concatenate('ATD_', Concatenate('ATD Cohort Year'p, '12_')), 'End Term'p)
ELSE ' '
This code block returns the string: 'ATD_201212_2014'n. I thought that adding the single quotes and the "n" around the column name would make SAS return the column but this didn't work either - it only returns a string.
IF ( ( 'ATD Cohort Year'p NotMissing ) AND ( 'End Term'p NotMissing ) )
RETURN Concatenate(Concatenate(Concatenate('\'ATD_', Concatenate('ATD Cohort Year'p, '12_')), 'End Term'p),'\'n')
ELSE ' '
The problem is, I don't want a string. I want the string to be evaluated as a variable and the contents of this variable returned. I think this feature would be helpful to many programmers.
Thanks for your consideration.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.