在Proc Transpose中处理重复性问题或文本

问题描述

你好,我有这个数据

Dataset

我需要执行这些编辑检查

”如果回答“受试者是否消耗了全部高脂肪/高热量 早餐?”是,则“如果否,受试者是否消耗了至少50% 高脂肪/高卡路里的早餐?禁食的问题一定不能 礼物”

”如果回答“受试者是否消耗了全部高脂肪/高热量 早餐?”是否,则“如果否,则受试者是否消耗了至少50% 高脂肪/高卡路里的早餐?空腹问题一定是 礼物”

”如果回答“受试者是否消耗了全部高脂肪/高热量 早餐?”是否,请回答“如果否,受试者是否在 高脂肪/高卡路里早餐中至少有50%?”必须存在”

我写了以下代码

   *data fq; 
 set dm.fq;  
 ptno=strip(compress(clientid,'-'))+0;
run;
proc sort; 
 by ptno period day hour;
run;
proc transpose data=fq out=tempfq  (DROP=_NAME_ _LABEL_); 
   by ptno period day hour;
   var fq_yn;
   id fq_qst; 
   run;
data final;
set tempfq;*

但是,我在日志中遇到以下错误

错误:ID值“ DID_THE_SUBJECT_FAST_AT_LEAST_4”在同一BY组中出现两次。

标题开始大写并被截短

Output

如何处理日志中的错误?如何在转置时扩展列宽以产生整个问题?

解决方法

您需要做两件事

  • 确定您要重复回答的问题,例如:
    • 对于occurs twice in the same BY group.
    • 您要2列,还是
    • 第一次出现的一列,或
    • 第二次出现中的一列,或
    • 如果同时出现YESYES,则包含NO的一列,或者
    • 如果同时出现NOYES,则包含NO的一列,或者
    • 如果同时出现MULTIYES,则包含NO的一列,或者
    • 如果YES,NO中的列按period,day,hour的顺序出现,则为{li>的一列,或者
    • 如果NO,YES中的列以period,hour的顺序出现,则列为NO,YES
    • 带有YES,NO的一列,而不考虑顺序
    • 带有YES(2)的一列,而不考虑顺序
    • 带有( freq )后缀的一列,例如NO(2)TRANSPOSE
    • 对于BY GROUP重复3次以上的案例有相同的想法
    • 每个想法都需要在IDLABEL之前对数据进行一些预处理
  • 在输出时,使用Proc TABULATE在列标题中包含整个原始问题。

透视调查数据可能对建模和预测有用,但是,如果出于报告目的而使用Proc REPORTID可能会更好。

可能的“修复”

BY组中的VAR值多次出现时,有多个ERROR:值进入单个枢轴目标。因此ptno period day hour

对于重复的问题,在SORT组中有相同答案的情况,您可以再按一个键FQ_QST,添加NODUPKEY并指定选项FQ_QST。进行这种排序后,不会出现FQ_YN的重复项,只有一个ID值通过proc sort NODUPKEY; by ptno period day hour FQ_QST; run; 旋转到一列中。

NODUPKEY

如果您的数据在组中包含重复的问题,并且问题的答案不同,则每个SORT剩余的答案取决于# importing libraries from keras.models import Sequential from keras.layers import Convolution2D from keras.layers import MaxPooling2D from keras.layers import Flatten from keras.layers import Dense from keras.layers import LSTM from keras.layers import TimeDistributed from keras.preprocessing.image import ImageDataGenerator train_datagen = ImageDataGenerator( rescale=1./255,shear_range=0.2,zoom_range=0.2,horizontal_flip=True) test_datagen = ImageDataGenerator(rescale=1./255) training_set = train_datagen.flow_from_directory( 'D:\\thesis\\Paper 3\\Feature Extraction\\two_dimension_Feature_extraction\\stft_feature\\Training_set',target_size=(64,64),batch_size=32,class_mode='binary') test_set = test_datagen.flow_from_directory( 'D:\\thesis\\Paper 3\\Feature Extraction\\two_dimension_Feature_extraction\\stft_feature\\Test_set',class_mode='binary') #initializing the CNN classifier = Sequential() #convolution2D classifier.add(TimeDistributed(Convolution2D(32,3,input_shape = (64,64,3),activation = 'relu'))) #32 feature detector with 3*3 dimensions,64*64 is the used format with 3 channel because the image is colored #adding maxpooling classifier.add(TimeDistributed(MaxPooling2D(2,2))) #Flattening classifier.add(TimeDistributed(Flatten())) classifier.add(TimeDistributed(classifier)) classifier.add(LSTM(units= 20,input_shape = (1,5),return_sequences = True )) classifier.add(LSTM(units = 20)) #Full Connection classifier.add(Dense(output_dim = 128,activation = 'relu')) classifier.add(Dense(output_dim = 1,activation = 'sigmoid')) #compiling the CNN classifier.compile(optimizer = 'adam',loss = 'binary_crossentropy',metrics = ['accuracy']) #Fitting the CNN to the images history = classifier.fit_generator(training_set,steps_per_epoch=2550,epochs=25,validation_data= test_set,validation_steps=510) import matplotlib.pyplot as plt acc = history.history['acc'] val_acc = history.history['val_acc'] loss = history.history['loss'] val_loss = history.history['val_loss'] epochs = range(1,len(acc) + 1) plt.plot(epochs,acc,'r',label='Training acc') plt.plot(epochs,val_acc,'b',label='Validation acc') plt.title('Training and validation accuracy') plt.legend() plt.figure() plt.plot(epochs,loss,label='Training loss') plt.plot(epochs,val_loss,label='Validation loss') plt.title('Training and validation loss') plt.plot() plt.legend() plt.show() test_loss,test_acc = classifier.evaluate(test_set) print('test_acc:',test_acc) 的运行方式。来自帮助:

如果SORT程序的输入是基本SAS引擎数据集,并且由SAS进行了排序,则可以预测输出BY组中的观察顺序。组中观察的顺序与创建时将其写入数据集的顺序相同。因为基本SAS引擎按照将观测值写入数据集的顺序维护观测值,所以PROC SORT会以相同的顺序读取观测值。在处理过程中,PROC SORT会使用稳定的排序算法来保持观测的顺序。使用稳定的排序算法是因为默认情况下设置了EQUALS选项。因此,由PROC SORT选择要写入给定BY组的输出数据集的观察值是具有定义该组的BY变量值的数据集中的第一个观察值。