楼主: 一眼瞬间
3115 20

[问答] 面板数据的转化,内详,万分感谢!在第二页添加了数据Sample的附件。 [推广有奖]

11
PhoenixHuang 发表于 2013-10-12 18:29:45
Excel宏。 我一向是这么解决的。 楼主可以把数据发过来我帮你写。

12
一眼瞬间 发表于 2013-10-13 02:26:06
PhoenixHuang 发表于 2013-10-12 18:29
Excel宏。 我一向是这么解决的。 楼主可以把数据发过来我帮你写。
谢谢LS!我整理下数据。

LS也是用从Datastream 里面下下来的数据么?我的意思是如果是相对比较大的数据,比如说10个变量,1000个公司,2年的daily数据,也能用excel做么?(我现在的数据没这么大哈)

13
yongyitian 发表于 2013-10-13 03:27:11
一眼瞬间 发表于 2013-10-12 12:56
Thank you so much!

Code1和code2分别是公司的identifier。只是我有上千个公司,不知道能不能不输入上 ...
If I understand correctly, you data have the SAME measures for each identifier (for example: p, WC02999 and WC04551 as shown in the first floor), and all the identifiers are numbers. Than the code is much simple, like this:

  1. data abc_1;
  2. set abc (rename=(code=date_c));
  3. array num{*} _numeric_;
  4. do i = 1 to dim(num) by 3;
  5. code = scan(vlabel(num[i]), 1, '()');
  6. p = num[i];
  7. p2 = num[i+1];
  8. p3 = num[i+2];
  9. output;
  10. end;
  11. keep date_c code p p2 p3;
  12. run;
复制代码

14
一眼瞬间 发表于 2013-10-13 07:35:10
yongyitian 发表于 2013-10-13 03:27
If I understand correctly, you data have the SAME measures for each identifier (for example: p,  ...
Hi Yongyitian,

Thank you so much.

This one looks really elegant. The identifiers are not all numbers, sometimes they are combination of numbers and characteristics.

Can I still do it?

Sorry that I did not describe it clearly.

Best regards!

15
yongyitian 发表于 2013-10-13 08:18:56
一眼瞬间 发表于 2013-10-13 07:35
Hi Yongyitian,

Thank you so much.
Sorry, I should say that the identifiers should start with numbers.
In that way, you can use vlabel function to get it.

It is assumed that the first row of excel file is used as variable names when PROC IMPORT it.
But when a variable name starts with a number such as 29060K(P), it will be used as label of the variable in the imported dataset.

It does not matter if there are letters following the first number. But if you also have identifiers that start with a letter (such as A29060K), you will be in trouble, since it will be used as a variable name.

Use proc contents data=yourdata; run; to check the variable names and labels.

16
一眼瞬间 发表于 2013-10-14 17:14:59
Hi Yitian,

I attached a sample file.

I think that your way works, just there seems to be some minor problems. When I imported the CSV file to SAS, the first row changed automatically. For example "36177N(P)" became  _36177N_P_.

In that way the first row start with a character.

The attached file is the xls file. CSV is not supported.

Would you help me out? Thank you so much!
I am looking forward to your reply.

Best regards!
好像主要问题是Import CSV file之后,first row并不是被当成label,而是变成了其他的格式。
我感觉已经很接近了,但是不知道应该改哪里。

这个数据里面有一列是error column,实在不行的话,可不可以手工把error column先给删掉,然后再reshape?


17
一眼瞬间 发表于 2013-10-14 17:16:23
Thank you very very much for your help.

18
一眼瞬间 发表于 2013-10-14 17:19:34
yongyitian 发表于 2013-10-13 08:18
Sorry, I should say that the identifiers should start with numbers.
In that way, you can use v ...
Sorry, I should have uploaded the data at the first place.

19
一眼瞬间 发表于 2013-10-15 03:48:36
手工改了下那个Error column,是不是比较可行些?

实际数据中如果error column比较多的话,貌似手工改动或者删除也挺麻烦的。

test1.xlsx

10.56 KB

20
yongyitian 发表于 2013-10-15 05:26:52
一眼瞬间 发表?2013-10-15 03:48
手工改了下那个Error column,是不是比较可行些?

实际数据中如果error column比较多的话,貌似手工改动 ...
The SAS name convention is like this:

The first character must be an English letter (A, B, C, . . ., Z) or underscore (_).
Subsequent characters can be letters, numeric digits (0, 1, . . ., 9), or underscores.
http://support.sas.com/documentation/cdl/en/lrcon/62955/HTML/default/viewer.htm#a000998953.htm

Your data does not have valid variable names according to the above sas rules:
But save csv to xls file then using proc import and the code at upper floor should work.

Note: the variable CODE is a type of num shown in the picture, so the do-loop should start from 2.

You also need to type the exact variable names for p, p1, p2 ...


VariableList.PNG



您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2025-12-22 15:51