Hi All,
I am trying to assign -ve numeric value to a macro variable in SAS symput statement but getting error below.
data one; infile datalines; input ID value ; datalines; -1 1234 -2 4567 -3 7890 -4 4321 ; run; data two; set one; call symput ( ID,value); run;
ERROR: Symbolic variable name -1 must begin with a letter or underscore.
Is there a way we can use -ve values without getting any error
Thanks
Kajal
There's no such thing as a macro variable whose name is -1. (Of course, you can have a macro variable with a valid name whose value is -1)
Please explain in words what you are trying to do here.
I am trying to create macro variable values from ID values whose values are under column 'value'
-1 will have a value 1234
-2 will have a value 4567
-3 will have a value 7890
-4 will have a value 4321
like this
@kajal_30 wrote:
I am trying to create macro variable values from ID values whose values are under column 'value'
-1 will have a value 1234
-2 will have a value 4567
-3 will have a value 7890
-4 will have a value 4321
like this
Explain why you want a macro variable to be named -1. Why does it have to be named -1, why can't it be named POMEGRANATE or ELEPHANT? How will this macro variable be used?
How exactly do expect to use that not-legally named variable?
This smells like trying to put way too much data into macro variables.
Is it possible to create format in sas without using hardcoded values but values from columns ?
@kajal_30 wrote:
Is it possible to create format in sas without using hardcoded values but values from columns ?
Yes. You have to create a data set with the needed values in the for specific variable names that the procedure expects to see.
data one; infile datalines; input ID value ; datalines; -1 1234 -2 4567 -3 7890 -4 4321 ; run; data fmtmaker; set one; fmtname='Id_to_Value'; type='N'; start=Id; label=Value; run; proc format library=work cntlin=fmtmaker; run; proc print data=one; var id; format id id_to_value.; run;
There are some elements a bit tricky about ranges of values the Other option in proc format for what to do with not listed values and whether you actually need a FORMAT or an INFORMAT.
Thanks but it won't resolve my purpose as I need to use those values in a table name for fetching info.
for eg: &var = 2401 then use this value for where table_name = dt_&var. where I can not use format values like this.
That is not a very clear description of how you are attempting to use this.
Any place you have the variable ID you can retrieve the text
Tablename = cats('dt_',put(id, id_to_value.));
And throwing around macro variables with values, where they are assigned or context doesn't clarify much.
Show the values you need, where you need them.
What you start with.
And we may be able to get there.
Assuming 'this won't work' without a clear description of what it is to be used for results in poor suggestions.
And if this related to the https://communities.sas.com/t5/SAS-Programming/Need-help-with-the-code-for-fetching-data-from-differ... post then why haven't you responded to suggestions there?
Exactly because I am trying a workaround and as I already clarified that I have values which I need to use to concatenate with other value to create a table name just a simple 1 line ask
have a value -2 associated to another value 1234
so I need to use 1234 in the table name that's it.
@kajal_30 wrote:
Exactly because I am trying a workaround and as I already clarified that I have values which I need to use to concatenate with other value to create a table name just a simple 1 line ask
have a value -2 associated to another value 1234
so I need to use 1234 in the table name that's it.
So, how does this not meet the need, using the format created above:
Tablename = cats('dt_',put(id, id_to_value.));
so you are suggesting below ?
Proc sql;
select * from sashelp.car_summary_cats('dt_',put(id, id_to_value.));
quit;
expecting it to resolve as below
Proc sql;
select * from sashelp.car_summary_2412;
quit;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.