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

Hi Everyone,

I cannot get SAS read the datalines below correctly into SAS file.

The record 4 and 5 have blank or missing value.

Can anyone help me with that?

Thank you so much.

HHC

 

data F3_final_list;
input name $32. value;

datalines;
D_VR_comgap_stb_lb6_ord3_d2_x1	100
D_W_VR_comgap_lb10_stb_cd_xac123	2 
D_std90_gt_90	0
QD_VRcomgap_stb_lb10_ord3_d1_x	
DW_VRcomgap_stb_lb6_ord3_d1_y	
D_sys2_cnt_trend_prior	0
;run;
1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User
data F3_final_list;
infile datalines truncover;
input name : $32. value;
datalines;
D_VR_comgap_stb_lb6_ord3_d2_x1	100
D_W_VR_comgap_lb10_stb_cd_xac123	2 
D_std90_gt_90	0
QD_VRcomgap_stb_lb10_ord3_d1_x	
DW_VRcomgap_stb_lb6_ord3_d1_y	
D_sys2_cnt_trend_prior	0
;run;

View solution in original post

7 REPLIES 7
ballardw
Super User

Please note that your data lines to not have a value for the value variable.

 

QD_VRcomgap_stb_lb10_ord3_d1_x

DW_VRcomgap_stb_lb6_ord3_d1_y

there is not second value on either of these lines.

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Do you mean the dsd option:

data F3_final_list;
  infile datalines dsd;
  input name $32. value;
datalines;
D_VR_comgap_stb_lb6_ord3_d2_x1	100
D_W_VR_comgap_lb10_stb_cd_xac123	2 
D_std90_gt_90	0
QD_VRcomgap_stb_lb10_ord3_d1_x	
DW_VRcomgap_stb_lb6_ord3_d1_y	
D_sys2_cnt_trend_prior	0
;run;
Astounding
PROC Star

The instruction $32. is incorrect.  It tells SAS to read 32 characters, regardless of whether they are blanks or characters following blanks.  A better way:

 

length name $ 32;

input name value;

 

Also, since some lines do not contain value, this statement belongs before the INPUT statement:

 

infile datalines truncover;

rogerjdeangelis
Barite | Level 11
When to use 'input; _infile_' combinations

this post
https://goo.gl/pv00gD
https://communities.sas.com/t5/forums/replypage/board-id/programming/message-id/80251

HAVE (missing data, oddly spaced data and unknown variable lengths in a SAS interactive old text editor)
=========================================================================================================

Because editors like EE, EG, SAS Studio are inconsistent with inline data, you may want stick with just one.
Line lengths, how blank lines are processed and '.' vary from editor to editor.
I like to stick with the 'old text editor', which was rock solid prior to 1984, but is deteriorating


HAVE
====

cards4;
D_VR_comgap_stb_lb6_ord3_d2_x1 100
D_W_VR_comgap_lb10_stb_cd_xac123 2
D_std90_gt_90 0
Q .
S .
QD_VRcomgap_stb_lb10_ord3_d1_x
DW_VRcomgap_stb_lb6_ord3_d1_y
D_sys2_cnt_trend_prior 0


WANT
====

Up to 40 obs WORK.F3_FINAL_LIST total obs=8

Obs NAME VALUE

1 D_VR_comgap_stb_lb6_ord3_d2_x1 100
2 D_W_VR_comgap_lb10_stb_cd_xac123 2
3 D_std90_gt_90 0
4 Q .
5 S .
6 QD_VRcomgap_stb_lb10_ord3_d1_x .
7 DW_VRcomgap_stb_lb6_ord3_d1_y .
8 D_sys2_cnt_trend_prior 0

WORKING CODE
============
input;
name=scan(_infile_,1,' ');
value=input(scan(_infile_,2,' '),4.);


FULL SOLUTION
=============


data F3_final_list;
length name $384 ; * longest editor line in old text editor;
input;
name=scan(_infile_,1,' ');
value=input(scan(_infile_,2,' '),4.);
cards4;
D_VR_comgap_stb_lb6_ord3_d2_x1 100
D_W_VR_comgap_lb10_stb_cd_xac123 2
D_std90_gt_90 0
Q .
S .
QD_VRcomgap_stb_lb10_ord3_d1_x
DW_VRcomgap_stb_lb6_ord3_d1_y
D_sys2_cnt_trend_prior 0
;;;;
run;quit;

2735 data F3_final_list;
2736 length name $384 ; * longest editor line in old text editor;
2737 input;
2738 name=scan(_infile_,1,' ');
2739 value=input(scan(_infile_,2,' '),4.);
2740 cards4;

NOTE: The data set WORK.F3_FINAL_LIST has 8 observations and 2 variables.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds


In the old text editor
If you save this in your autocall library and turn on the command macros, 'options cmdmac;'


Hight light the cards data and type 'cuth' on the clean old text editor command line

%macro cuth/cmd;
%do i=1 %to 20;
c ' ' ' ' all;
%end;
%mend cuth;

You can also use a function key ie 'F1 cuth'

HIGHLIGHT THIS

D_VR_comgap_stb_lb6_ord3_d2_x1 100
D_W_VR_comgap_lb10_stb_cd_xac123 2
D_std90_gt_90 0
Q .
S .
QD_VRcomgap_stb_lb10_ord3_d1_x
DW_VRcomgap_stb_lb6_ord3_d1_y
D_sys2_cnt_trend_prior 0

YOU GET THIS

D_VR_comgap_stb_lb6_ord3_d2_x1 100
D_W_VR_comgap_lb10_stb_cd_xac123 2
D_std90_gt_90 0
Q .
S .
QD_VRcomgap_stb_lb10_ord3_d1_x
DW_VRcomgap_stb_lb6_ord3_d1_y
D_sys2_cnt_trend_prior 0


2734 run;quit;
MLOGIC(CUTH): Beginning execution.
MLOGIC(CUTH): This macro was compiled from the autocall file c:\oto\cuth.sas
MLOGIC(CUTH): %DO loop beginning; index variable I; start value is 1; stop value is 20; by value is 1.
MLOGIC(CUTH): %DO loop index variable I is now 2; loop will iterate again.
MLOGIC(CUTH): %DO loop index variable I is now 3; loop will iterate again.
MLOGIC(CUTH): %DO loop index variable I is now 4; loop will iterate again.
MLOGIC(CUTH): %DO loop index variable I is now 5; loop will iterate again.
MLOGIC(CUTH): %DO loop index variable I is now 6; loop will iterate again.
MLOGIC(CUTH): %DO loop index variable I is now 7; loop will iterate again.
MLOGIC(CUTH): %DO loop index variable I is now 8; loop will iterate again.
MLOGIC(CUTH): %DO loop index variable I is now 9; loop will iterate again.
MLOGIC(CUTH): %DO loop index variable I is now 10; loop will iterate again.
MLOGIC(CUTH): %DO loop index variable I is now 11; loop will iterate again.
MLOGIC(CUTH): %DO loop index variable I is now 12; loop will iterate again.
MLOGIC(CUTH): %DO loop index variable I is now 13; loop will iterate again.
MLOGIC(CUTH): %DO loop index variable I is now 14; loop will iterate again.
MLOGIC(CUTH): %DO loop index variable I is now 15; loop will iterate again.
MLOGIC(CUTH): %DO loop index variable I is now 16; loop will iterate again.
MLOGIC(CUTH): %DO loop index variable I is now 17; loop will iterate again.
MLOGIC(CUTH): %DO loop index variable I is now 18; loop will iterate again.
MLOGIC(CUTH): %DO loop index variable I is now 19; loop will iterate again.
MLOGIC(CUTH): %DO loop index variable I is now 20; loop will iterate again.
MLOGIC(CUTH): %DO loop index variable I is now 21; loop will not iterate again.
MLOGIC(CUTH): Ending execution.


rogerjdeangelis
Barite | Level 11

When to use 'input; _infile_' combinations

formatting not working this is a retry

see
https://goo.gl/pv00gD
https://communities.sas.com/t5/forums/replypage/board-id/programming/message-id/80251

HAVE  (missing data, oddly spaced data and unknown variable lengths in a SAS interactive old text editor)
=========================================================================================================

Because editors like EE, EG, SAS Studio are inconsistent with inline data, you may want stick with just one.
Line lengths, how blank lines are processed and '.' may vary.
I like to stick with the 'old text editor', which was rock solid prior to 1984?


HAVE
====

cards4;

D_VR_comgap_stb_lb6_ord3_d2_x1      100
D_W_VR_comgap_lb10_stb_cd_xac123                        2
D_std90_gt_90  0
Q .
S                   .
QD_VRcomgap_stb_lb10_ord3_d1_x
DW_VRcomgap_stb_lb6_ord3_d1_y
D_sys2_cnt_trend_prior                        0


WANT
====

Up to 40 obs WORK.F3_FINAL_LIST total obs=8

Obs    NAME                                VALUE

 1     D_VR_comgap_stb_lb6_ord3_d2_x1       100
 2     D_W_VR_comgap_lb10_stb_cd_xac123       2
 3     D_std90_gt_90                          0
 4     Q                                      .
 5     S                                      .
 6     QD_VRcomgap_stb_lb10_ord3_d1_x         .
 7     DW_VRcomgap_stb_lb6_ord3_d1_y          .
 8     D_sys2_cnt_trend_prior                 0

WORKING CODE
============
   input;
   name=scan(_infile_,1,' ');
   value=input(scan(_infile_,2,' '),4.);


FULL SOLUTION
=============


data F3_final_list;
  length name  $384 ; * longest editor line in old text editor;
  input;
  name=scan(_infile_,1,' ');
  value=input(scan(_infile_,2,' '),4.);
cards4;
D_VR_comgap_stb_lb6_ord3_d2_x1      100
D_W_VR_comgap_lb10_stb_cd_xac123                        2
D_std90_gt_90  0
Q .
S                   .
QD_VRcomgap_stb_lb10_ord3_d1_x
DW_VRcomgap_stb_lb6_ord3_d1_y
D_sys2_cnt_trend_prior                        0
;;;;
run;quit;

2735  data F3_final_list;
2736    length name  $384 ; * longest editor line in old text editor;
2737    input;
2738    name=scan(_infile_,1,' ');
2739    value=input(scan(_infile_,2,' '),4.);
2740  cards4;

NOTE: The data set WORK.F3_FINAL_LIST has 8 observations and 2 variables.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds


In the old text editor
If you save this in your autocall library and turn on the command macros, 'options cmdmac;'


Hight light the cards data and type 'cuth' on the clean old text editor command line

%macro cuth/cmd;
  %do i=1 %to 20;
    c '  ' ' ' all;
  %end;
%mend cuth;

You can also use a function key   ie  'F1  cuth'

HIGHLIGHT THIS

D_VR_comgap_stb_lb6_ord3_d2_x1      100
D_W_VR_comgap_lb10_stb_cd_xac123                        2
D_std90_gt_90  0
Q .
S                   .
QD_VRcomgap_stb_lb10_ord3_d1_x
DW_VRcomgap_stb_lb6_ord3_d1_y
D_sys2_cnt_trend_prior                        0

YOU GET THIS

D_VR_comgap_stb_lb6_ord3_d2_x1 100
D_W_VR_comgap_lb10_stb_cd_xac123 2
D_std90_gt_90 0
Q .
S .
QD_VRcomgap_stb_lb10_ord3_d1_x
DW_VRcomgap_stb_lb6_ord3_d1_y
D_sys2_cnt_trend_prior 0


2734  run;quit;
MLOGIC(CUTH):  Beginning execution.
MLOGIC(CUTH):  This macro was compiled from the autocall file c:\oto\cuth.sas
MLOGIC(CUTH):  %DO loop beginning; index variable I; start value is 1; stop value is 20; by value is 1.
MLOGIC(CUTH):  %DO loop index variable I is now 2; loop will iterate again.
MLOGIC(CUTH):  %DO loop index variable I is now 3; loop will iterate again.
MLOGIC(CUTH):  %DO loop index variable I is now 4; loop will iterate again.
MLOGIC(CUTH):  %DO loop index variable I is now 5; loop will iterate again.
MLOGIC(CUTH):  %DO loop index variable I is now 6; loop will iterate again.
MLOGIC(CUTH):  %DO loop index variable I is now 7; loop will iterate again.
MLOGIC(CUTH):  %DO loop index variable I is now 8; loop will iterate again.
MLOGIC(CUTH):  %DO loop index variable I is now 9; loop will iterate again.
MLOGIC(CUTH):  %DO loop index variable I is now 10; loop will iterate again.
MLOGIC(CUTH):  %DO loop index variable I is now 11; loop will iterate again.
MLOGIC(CUTH):  %DO loop index variable I is now 12; loop will iterate again.
MLOGIC(CUTH):  %DO loop index variable I is now 13; loop will iterate again.
MLOGIC(CUTH):  %DO loop index variable I is now 14; loop will iterate again.
MLOGIC(CUTH):  %DO loop index variable I is now 15; loop will iterate again.
MLOGIC(CUTH):  %DO loop index variable I is now 16; loop will iterate again.
MLOGIC(CUTH):  %DO loop index variable I is now 17; loop will iterate again.
MLOGIC(CUTH):  %DO loop index variable I is now 18; loop will iterate again.
MLOGIC(CUTH):  %DO loop index variable I is now 19; loop will iterate again.
MLOGIC(CUTH): %DO loop index variable I is now 20; loop will iterate again.
MLOGIC(CUTH):  %DO loop index variable I is now 21; loop will not iterate again.
MLOGIC(CUTH):  Ending execution.



Ksharp
Super User
data F3_final_list;
infile datalines truncover;
input name : $32. value;
datalines;
D_VR_comgap_stb_lb6_ord3_d2_x1	100
D_W_VR_comgap_lb10_stb_cd_xac123	2 
D_std90_gt_90	0
QD_VRcomgap_stb_lb10_ord3_d1_x	
DW_VRcomgap_stb_lb6_ord3_d1_y	
D_sys2_cnt_trend_prior	0
;run;
hhchenfx
Barite | Level 11

Thank you so much.

Both codes work nicely.

HHC

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 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.

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
  • 7 replies
  • 1050 views
  • 1 like
  • 6 in conversation