Hello team,
I have this code, it is not showing anything in the log:
Thanks,
Blue Blue
Data _NULL_; Set SAShelp._CMPIDX_; Call symput('ABC',key); Run; %put &ABC;
@GN0001
I cut/pasted your code into a SAS session, and there is output in the log:
85 Data _NULL_;
586 Set SAShelp._CMPIDX_;
587 Call symput('ABC',key);
588 Run;
NOTE: There were 44 observations read from the data set SASHELP._CMPIDX_.
NOTE: DATA statement used (Total process time):
real time 0.06 seconds
cpu time 0.03 seconds
589
590 %put &ABC;
stat
I suspect that you have unbalanced quotes somewhere in your SAS session. Close SAS, then reopen cut/paste the code you provided, and submit that. Then cut/paste the log to this thread.
Please show the complete log from that code.
@GN0001
I cut/pasted your code into a SAS session, and there is output in the log:
85 Data _NULL_;
586 Set SAShelp._CMPIDX_;
587 Call symput('ABC',key);
588 Run;
NOTE: There were 44 observations read from the data set SASHELP._CMPIDX_.
NOTE: DATA statement used (Total process time):
real time 0.06 seconds
cpu time 0.03 seconds
589
590 %put &ABC;
stat
I suspect that you have unbalanced quotes somewhere in your SAS session. Close SAS, then reopen cut/paste the code you provided, and submit that. Then cut/paste the log to this thread.
Using the log from @AMSAS , it looks like %put &ABC; produces the output stat, which would be correct. So, @GN0001 , we really need to see your complete log (including the actual code and any output, any WARNINGs ERRORs and NOTEs). For your future benefit, when there are problems in the log, then SHOW US the log.
I have rerun the code and the code perform well as written.
The last value of key is "stat" and that is reproduced in the log.
Perhaps @GN0001 had something other in mind.
The results of my run are as follows.
Data _NULL_;
Set SAShelp._CMPIDX_;
Call symput('ABC',key);
Run;
%put &=ABC;
The complete log is as follows
1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
72
73 Data _NULL_;
74 Set SAShelp._CMPIDX_;
75 Call symput('ABC',key);
76 Run;
NOTE: There were 44 observations read from the data set SASHELP._CMPIDX_.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
user cpu time 0.00 seconds
system cpu time 0.00 seconds
memory 622.65k
OS Memory 31396.00k
Timestamp 05/13/2021 12:18:39 PM
Step Count 96 Switch Count 0
Page Faults 0
Page Reclaims 92
Page Swaps 0
Voluntary Context Switches 0
Involuntary Context Switches 0
Block Input Operations 0
Block Output Operations 0
77
78 %put &=ABC;
ABC=stat
79
80 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
92
@GN0001 wrote:
Hello,
It is only showing the last observation?
Why?
Respectfully,
Blue Blue
Because the CALL SYMPUT(X) routine will "overwrite" the macro variable every time it is called.
What do we need to do to write all the values of a variable in a dataset?
Are you referring that call symput returns only one value because the previous value is overwritten by a new call of macro?
Let me test a code and I will get back to you.
I am totally confused. I run the code and it doesn't show anything on the log. It has to show some value on the log.
Right now this code shows only code itself on the log and I can't understand why:
data have;
input name $ value $;
datalines;
a 1
b x
c f3
;
data _null_;
set have;
call symputx(name,value);
run;
Regards,
Blue Blue
I ran the code you provided and it returns the following in the log, which is what I would expect in the SAS log.
1999 data have;
2000 input name $ value $;
2001 datalines;
NOTE: The data set WORK.HAVE has 3 observations and 2 variables.
NOTE: DATA statement used (Total process time):
real time 0.03 seconds
cpu time 0.01 seconds
2005 ;
2006
2007 data _null_;
2008 set have;
2009 call symputx(name,value);
2010 run;
NOTE: There were 3 observations read from the data set WORK.HAVE.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds
Having said that, your first sentence "What do we need to do to write all the values of a variable in a dataset?" appears to indicate that you expect the second data step to create a SAS Data set that contains all the variables in the "have" dataset.
If this is correct then you don't need the call symputx and need to replace _null_ with your output data set name, which will result in this SAS log:
2011 data have;
2012 input name $ value $;
2013 datalines;
NOTE: The data set WORK.HAVE has 3 observations and 2 variables.
NOTE: DATA statement used (Total process time):
real time 0.02 seconds
cpu time 0.01 seconds
2017 ;
2018
2019 data want ;
2020 set have;
2021 run;
NOTE: There were 3 observations read from the data set WORK.HAVE.
NOTE: The data set WORK.WANT has 3 observations and 2 variables.
NOTE: DATA statement used (Total process time):
real time 0.04 seconds
cpu time 0.04 seconds
If you want to just put the values of variables name and value to the log then add a PUT statement:
2022 data have;
2023 input name $ value $;
2024 datalines;
NOTE: The data set WORK.HAVE has 3 observations and 2 variables.
NOTE: DATA statement used (Total process time):
real time 0.02 seconds
cpu time 0.01 seconds
2028 ;
2029
2030 data want ;
2031 set have;
2032 put name= value= ;
2033 run;
name=a value=1
name=b value=x
name=c value=f3
NOTE: There were 3 observations read from the data set WORK.HAVE.
NOTE: The data set WORK.WANT has 3 observations and 2 variables.
NOTE: DATA statement used (Total process time):
real time 0.02 seconds
cpu time 0.01 seconds
It's not clear to me what you want to achieve, or what you expect as output. If you could provide a more detailed explanation of what you have and what you expect to get as a result then I'm sure someone will be able to help you further.
@GN0001 wrote:
Hello,
It is only showing the last observation?
Why?
Respectfully,
Blue Blue
Each observation of the data set replaces the value of the macro variable. So when you get to the end of the data set, the macro variable contains the last value in the data set.
As stated by others: what are you trying to accomplish, what is the goal here?
what you explained suffice what I am looking for.
Thanks,
Blue Blue
@GN0001 wrote:
what you explained suffice what I am looking for.
Thanks,
Blue Blue
Great, but what is the goal? What are you trying to do with a macro variable here? Why did you put a CALL SYMPUT at the end of that data step?
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.