I have below data in X dataset;
BRAND PRICE
---------- --------------
Apple 50000
Samsung 20000
MI 15000
LG 35000
Now I need a below values in 'get' macro variable.
get value:
============
Apple(50000),Samsung(20000),MI(15000),LG(35000).
Please suggest me which one is a easiest way to do above. Thanks in advance.
Like this?
data X;
input BRAND $ PRICE;
datalines;
Apple 50000
Samsung 20000
MI 15000
LG 35000
;
data help(keep=var);
set X;
var = cats(BRAND,'(',PRICE,')');
run;
proc sql noprint;
select var INTO: get separated BY ','
from help;
quit;
%put &get;
So you want get_value to be a macro variable containing the value Apple(50000),Samsung(20000),MI(15000),LG(35000)?
Yes. Need complete value in macro varaible.
Like this?
data X;
input BRAND $ PRICE;
datalines;
Apple 50000
Samsung 20000
MI 15000
LG 35000
;
data help(keep=var);
set X;
var = cats(BRAND,'(',PRICE,')');
run;
proc sql noprint;
select var INTO: get separated BY ','
from help;
quit;
%put &get;
Great. It's working great, Thank you.
Now I want to keep this value in email and am using below. But macro variable is not working.
Can you sugegst me why?
x %tslit(Total sales are as follows: &get."
| mailx -s "Report" xxxxxx@xxx.com);
I am getting mail woth out resolving macro varibale.
Sorry..Please find correct code below.
x %tslit(echo "Total sales are as follows: &get."
| mailx -s "Report" xxxxxx@xxx.com);
I dont understand your question, please elaborate.
Initially we keep the value in macro variable,now needs to include that macro variable value in email using X coomand.
In that &get value is not resolving in X command. Please see my code in previous post.
X command is for invoking Operating System commands - nothing to do with SAS - so do you have an Operating System command:
%tslit
Unlikely, that looks like a SAS macro call.
Another problem, per my previous message, when your data gets large you will break then subject line limits. A good way to data into an email is to put it out from a dataset:
filename mailbox email 'someone@world.com' subject='Total Sales'; data _null_; file mailbox; set your_data; if _n_=1 then do; put "Hello"; put "This is a the Total Sales"; end; put _all_; run; filename mailbox clear;
You can find further examples, such as attaching reports, here:
I tried this way.but getting an error like connection was refsued. Don't have proper setup to execute above one.
Using X command other macro variables are resolving,but above macro variable is not resolving.it might due to large value or some other reason. Thanks.
When you get a connection refused, your mail setup is not working at all. Verify that you can send a simple mail before you embark in more complex things.
Also provide the complete code of the macro %tslit, so we can get a feeling for what it's supposed to do. Note that your X statement will finish before you start sending mail.
But make sure that you can send mail from SAS first.
Well, as always, my first question will be why? Macro is a text find and replace tool, it is not for data processing, that is what datasteps are for. If you go down that route you will effectively double the complexity of your code and obfuscate it to a certain degree. Also you will likely hit the boundaries of lengths of variables, and certain characters within there. So I wouldn't recommed this approach. There are numerous methods of working with data with are both more effective and simpler to work with. Provide some background and will be able to suggest.
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: