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

Hi all,

I am trying to use a special SAS code. In order to use it I have to have a data set with 2 variables ID and PCODE. ID is $12 and PCODE is a $6. I am importing this data set from a csv file using proc import.  The csv file looks like this:

pcode id
T0B3M2 724806
T0L0K0 2241906
T0K2S0 2559858
T1M0B1 3115006
T6L4S4 4527226
T5R1E9 6093226
T2A6K3 6927026
T8V7G7 7186848
T7S1N9 8380906
T0L1R0 9075136
T0E2M0 9232706
T0H3C0 10004336
T5X1G5 10106718
T8L5G3 10682226
T8A1R5 13721906
T3E7C4 15817336

 

However, I am unable to make the main SAS code that is supposed to use this data set as input to work. Someone has suggested that I should make the ID values left-justified.  Aren't all the character values in SAS automatically left-justified? If not how can I left-justify them? I have attached the data set that I have made from the csv file here. BTW, I am using SAS 9.4.

 

Many thanks, 

1 ACCEPTED SOLUTION

Accepted Solutions
Shmuel
Garnet | Level 18

The message "... lines included ..." means there is a statement starting with %include - followed with a text file name containing some code.

 

Locate that code <file name>.sas and open with notepad or notepad++,

locate the long lines and split them and finally save.

If you saved it in a different name then the original, don't forget to change

that statement starting with %include to the new name.

 

%include could be abbreviated as %inc.

 

Then run your program.

 

View solution in original post

10 REPLIES 10
Shmuel
Garnet | Level 18

Internal sas datasets' structure is different per OS, so posting a sas dataset doesn'n help much.

 

Char-type variables which are imported by PROC IMPORT are left justified.

Check by PROC CONTENTS is PCODE realy a char-type or numeric.

 

Please explain what issue you have because of justification, what code

you try to run and what are the results v.s. the expected results.

Primavera
Quartz | Level 8

Hello again,

 thank you for your help. I am figuring out that my problem is deeper than left-justification of my data. I am trying to use a program called  PCCFPlus_7C that was created by Stats Canada. I need to use it to get some statistical info about some study participants based on their postal codes. When I try to open the program I get:

Primavera_0-1593035159671.png

 

The result is that many of the lines in the program are truncated and thus the program does not work. Do you know how I can fix this issue? I am using  SAS 9.4 (Unicode Support) and my OS is Windows 10 (64-bit). 

 

Many Thanks 

Shmuel
Garnet | Level 18

The message "... lines included ..." means there is a statement starting with %include - followed with a text file name containing some code.

 

Locate that code <file name>.sas and open with notepad or notepad++,

locate the long lines and split them and finally save.

If you saved it in a different name then the original, don't forget to change

that statement starting with %include to the new name.

 

%include could be abbreviated as %inc.

 

Then run your program.

 

Primavera
Quartz | Level 8
Awesome. It worked. Thanks 🙂
Tom
Super User Tom
Super User

What gave you that pop-up error message?

Did you try to include the file into the program editor window in SAS Display Manager?

Primavera
Quartz | Level 8

I just tried to open the program in the program editor window in SAS Display Manager. Nothing fancy. I have done that with my own codes at least 500 times before and never had seen this error. 

ballardw
Super User

It will depend on how a variable is created whether it will have leading spaces or not. Proc Import is not very bright. Look in your CSV file and see if the ID values appear in quotes like

"T0B3M2","      724806"

Your values in that data set have leading spaces.

data _null_;
set postcode4 (obs=1);
z=length(id);
a = length(strip(id));
put 'ID length is ' z 'length without leading spaces is ' a ;
run;

The log will show how long the first value of the ID variable as is  and after removing the leading spaces.

Good news is that it is easy to get rid of them:

Data want;
   set postcode4;
   id=strip(id);
run;

Tom
Super User Tom
Super User

Please show what the CSV file looks like, what you posted looks like a printout or a spreadsheet, a CSV file is text delimited with commas.

If you used PROC IMPORT to read the CSV file and the values in the ID variable only include digits, like in your example printout, then PROC IMPORT will assume the value is numeric.  Just write your own data step to read the file so you can control what type of variable is created.

data want;
  infile 'myfile.csv' dsd truncover firstobs=2;
  input pcode :$6.  id :$12.;
run;
Kurt_Bremser
Super User

When you need to post csv files for reference, do this:

  • open the file with a text editor (do NOT use Excel!)
  • mark the first few lines completely; enough so that edge cases (if present in the file) are covered
  • copy the text to the clipboard
  • open a subwindow with this button:
    Bildschirmfoto 2020-04-07 um 08.32.59.jpg
  • paste the text into this window

 

I inspected your dataset and found that id is in fact character with a length of 12. So I ran this code to left-justify it:

data pcode;
set postcode4;
id = left(id);
run;

 

Primavera
Quartz | Level 8

Hello again,

 thank you for your help and advice. Your code worked perfectly. But it seems my problem is deeper than that. I am trying to use a program called  PCCFPlus_7C that was created by Stats Canada. I need to use it to get some statistical info about some study participants based on their postal codes. When I try to open the program I get:

Primavera_0-1593035159671.png

 

The result is that many of the lines in the program are truncated and thus the program does not work. Since you are a super user do you know how I can fix this issue? I am using  SAS 9.4 (Unicode Support) and my OS is Windows 10 (64-bit). 

 

Many Thanks 

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 10 replies
  • 4427 views
  • 0 likes
  • 5 in conversation