BookmarkSubscribeRSS Feed
deleted_user
Not applicable
I have data sets in excel that I want to bring into SAS. They are structured like this.

Company Date var1 var2 var3
ABC 1/2/05
2 q 1
3 d 2
4 e 4
DEF 1/2/06
4 e 5
5 e 7

The number of observations per company vary. What I want to do is to spread the company and date information across the corresponding var information.
2 REPLIES 2
Peter_C
Rhodochrosite | Level 12
sounds like a minor task for a data step.

Just read a line and hold it; identify it's type and read relevant variables; if it is a company heading "RETAIN" those values; if it is a regular set of variables, "OUTPUT" a data row.

You may want these data in separate tables. The DATA statement allows more than one output data set to be defined. The OUTPUT statement allows you to nominate the table into which the row should be written.

There may even be an example in the manual. Search for "reading hierarchical files". I think that is the terminology for your data structure.

Good Luck

PeterC
Cynthia_sas
SAS Super FREQ
Hi:
I'm having trouble envisioning what your Excel sheet looks like.

Option 1: 5 columns with variable names in row 1 and company and date on a row by themselves:
[pre]
A B C D E
1 Company Date var1 var2 var3
2 ABC 1/2/05
3 2 q 1
4 3 d 2
5 4 e 4
6 DEF 1/2/06
7 4 e 5
8 5 e 7
[/pre]

Option 2: company name is only on row 1 of the group and var1-var3 have values on the company row:
[pre]
A B C D E
1 Company Date var1 var2 var3
2 ABC 1/2/05 2 q 1
3 3 d 2
4 4 e 4
5 DEF 1/2/06 4 e 5
6 5 e 7
[/pre]

Option 3: 3 columns where column A and Column B are being used differently on every row:
[pre]
A B C
1 ABC 1/2/05
2 2 q 1
3 3 d 2
4 4 e 4
5 DEF 1/2/06
6 4 e 5
7 5 e 7
[/pre]

It doesn't make a LOT of difference, the first 2 options for how the data will be read in probably is going to take a data step program with a RETAIN statement. The 3rd option might require a bit more data manipulation in addition to a RETAIN statement.

cynthia

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!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 2 replies
  • 857 views
  • 0 likes
  • 3 in conversation