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

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.

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

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;

View solution in original post

11 REPLIES 11
PeterClemmensen
Tourmaline | Level 20

So you want get_value to be a macro variable containing the value Apple(50000),Samsung(20000),MI(15000),LG(35000)?

Banu
Obsidian | Level 7

Yes. Need complete value in macro varaible.

PeterClemmensen
Tourmaline | Level 20

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;
Banu
Obsidian | Level 7

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.

 

Banu
Obsidian | Level 7

Sorry..Please find correct code below.

 

x %tslit(echo "Total sales are as follows: &get."

| mailx -s "Report" xxxxxx@xxx.com);

PeterClemmensen
Tourmaline | Level 20

I dont understand your question, please elaborate.

Banu
Obsidian | Level 7

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.

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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:

http://www2.sas.com/proceedings/forum2008/038-2008.pdf

Banu
Obsidian | Level 7

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.

Kurt_Bremser
Super User

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.

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 11 replies
  • 2994 views
  • 4 likes
  • 4 in conversation