BookmarkSubscribeRSS Feed
SmcGarrett
Obsidian | Level 7

Hello,

 

I have a data set with a customer ID and multiple variables for different transactions. 

 

Each transaction is a new observation so the customer ID is duplicated. The transactions are within a macro variable "&R".

 

I believe I need to execute a "do-loop" within proc sql but I am having trouble. 

 

I have:

CIDFirst VisitReturn VisitOrderRevenue
ABC1000
ABC0100
ABC0100
ABC0100
ABC01150

 

And I want:

CIDFirst VisitReturn VisitOrderRevenue
ABC14150

 

Any help is greatly appreciated. 

 

Michael

5 REPLIES 5
TomKari
Onyx | Level 15

This would be quite straightforward if your observations were in a SAS dataset. Do they need to be in a macro variable? What form do they take in the variable?

 

Tom

SmcGarrett
Obsidian | Level 7

The data is read into a SAS dataset. I just used excel for this purpose. 

 

Yes, they do need to be in a macro variable. 

 

The data is re-run weekly so the transactions will change if there are no orders or revenue or others... (there are over 15 different transactions")

 

The data is originally read in a text format and I use a scan function to read the values that exist in the "Transacation Type" field and then use a do loop to create columns for each transaction. So if I specify the Transaction Types without doing a scan, I run the risk of losing transactions that are different from one week to the next. 

 

They are all numeric. 

TomKari
Onyx | Level 15

Since you have your data in a macro variable, I can't think of any other way than DATA STEP programming to do your summarization.

 

If your variables were in a SAS dataset, I believe the following would meet your needs.

 

Tom

 

proc sql noprint;

create table Want as

select CID, sum(FirstVisit) as SumFirstVisit, sum(ReturnVisit) as SumReturnVisit, sum(Order) as SumOrder, sum(Revenue) as SumRevenue

from Have

group by CID;

quit;

Reeza
Super User

I don't agree that you need your macro variables. 

Explain your process further, it should be possible to accommodate your issues within a data step or proc SQL. Maybe include a case where you feel macros have to be involved. 

 

It looks like a proc summary would work but I'm probably missing something. 

 

Reeza
Super User

Also, are you posting in Data Management because your using DI Studio or because of the subject of your question. 

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to connect to databases in SAS Viya

Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 5 replies
  • 3380 views
  • 1 like
  • 3 in conversation