BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
dhavalyparikh
Obsidian | Level 7

%macro Update_table(a, id, c) ;

 

prc sql noprint ;

select id into :id  from libnew.table1 where program="&a"

select value into :username from SASHelp.vmacro where name = 'sysuserid'

run;

%put &username;

 

Proc SQL;

update table1

set Username = &username

where id = &id.;

run;

%mend Update_table;

 

The issue is I want to use :username result value with my update. I just want to know what's the best way to use :username variable in the update so I can update the value stored in the username variable.

 

1 ACCEPTED SOLUTION

Accepted Solutions
SASKiwi
PROC Star

Given the variables you are trying to update are character then they need to be enclosed in double quotes to resolve correctly:

%macro Update_table(a, id, c) ;

prc sql noprint ;
select id into :id  from libnew.table1 where program="&a"
select value into :username from SASHelp.vmacro where name = 'sysuserid'
run;

%put &username;


Proc SQL;
update table1
set Username = "&username"
where id = "&id.";
run;

%mend Update_table;

 

View solution in original post

5 REPLIES 5
SASKiwi
PROC Star

Given the variables you are trying to update are character then they need to be enclosed in double quotes to resolve correctly:

%macro Update_table(a, id, c) ;

prc sql noprint ;
select id into :id  from libnew.table1 where program="&a"
select value into :username from SASHelp.vmacro where name = 'sysuserid'
run;

%put &username;


Proc SQL;
update table1
set Username = "&username"
where id = "&id.";
run;

%mend Update_table;

 

dhavalyparikh
Obsidian | Level 7

Thanks. That works!

Kurt_Bremser
Super User

Why so complicated?

select value into :username from SASHelp.vmacro where name = 'sysuserid'

is equivalent to

%let username = &sysuserid.;

But you can directly use SYSUSERID in your SQL:

proc SQL;
update table1
set Username = "&sysuserid."
where id = &id.;
quit;

SQL statements are executed immediately, so no RUN is needed, but a QUIT to end the procedure.

Ksharp
Super User
You could use the following to check the list of all the system macro variable, And refer it directly :


%put _all_;

%put &=SYSUSERID ;
Tom
Super User Tom
Super User

If you want the value of SYSUSERID then just reference it directly. No need to run any queries.

proc SQL;
update table1
  set Username = "&sysuserid"
  where id in (select id from libnew.table1 where program="&a")
;
quit;

But you could also just use the SQL keyword USER.   That will have the same value as SYSUSERID.

proc SQL;
update table1
  set Username = USER
  where id in (select id from libnew.table1 where program="&a")
;
quit;

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
  • 697 views
  • 4 likes
  • 5 in conversation