BookmarkSubscribeRSS Feed
kajal_30
Quartz | Level 8

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

19 REPLIES 19
ChrisNZ
Tourmaline | Level 20
You're using the value as the variable name. Variable names cannot contain a hyphen.
PaigeMiller
Diamond | Level 26

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.

--
Paige Miller
kajal_30
Quartz | Level 8

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

ChrisNZ
Tourmaline | Level 20
Read the replies again. You can't do that.
PaigeMiller
Diamond | Level 26

@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?

--
Paige Miller
ballardw
Super User

How exactly do expect to use that not-legally named variable?

This smells like trying to put way too much data into macro variables.

ChrisNZ
Tourmaline | Level 20
It sounds like you might want to use formats. What's the final use?

Otherwise you can call the variable something like MINUS1.
kajal_30
Quartz | Level 8

Is it possible to create format in sas without using hardcoded values but values from columns  ? 

ballardw
Super User

@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.

kajal_30
Quartz | Level 8

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. 

ballardw
Super User

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?

kajal_30
Quartz | Level 8

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.  

 

 

ballardw
Super User

@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.));

 

kajal_30
Quartz | Level 8

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;

SAS Innovate 2025: Register Now

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!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 19 replies
  • 1233 views
  • 0 likes
  • 5 in conversation